Skip to content

Commit

Permalink
ItemPicker - overlay closed, ensure focus
Browse files Browse the repository at this point in the history
A small change, for part of the Accessibility review #41.

Uses Umbraco's `focusService` to remember the current focus
state before the ItemPicker's overlay is opened. Once it is closed,
the focus state is restored.
  • Loading branch information
leekelleher committed Apr 16, 2021
1 parent 429dbad commit 805401a
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.ItemPicker.Controller", [
"$scope",
"editorService",
"focusService",
"localizationService",
"overlayService",
function ($scope, editorService, localizationService, overlayService) {
function ($scope, editorService, focusService, localizationService, overlayService) {

// console.log("item-picker.model", $scope.model);

Expand Down Expand Up @@ -87,6 +88,8 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.

function add() {

focusService.rememberFocus();

var items = Object.toBoolean(config.allowDuplicates)
? config.items
: config.items.filter(x => vm.items.some(y => x.value === y.value) === false);
Expand Down Expand Up @@ -115,17 +118,22 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
vm.allowAdd = false;
}

setDirty();

editorService.close();

setDirty();
setFocus();
},
close: function () {
editorService.close();
setFocus();
}
});
};

function remove($index) {

focusService.rememberFocus();

if (config.confirmRemoval === true) {
var keys = ["contentment_removeItemMessage", "general_remove", "general_cancel", "contentment_removeItemButton"];
localizationService.localizeMany(keys).then(function (data) {
Expand All @@ -141,6 +149,7 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
},
close: function () {
overlayService.close();
setFocus();
}
});
});
Expand Down Expand Up @@ -168,6 +177,13 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
}
};

function setFocus() {
var lastKnownFocus = focusService.getLastKnownFocus();
if (lastKnownFocus) {
lastKnownFocus.focus();
}
};

init();
}
]);

0 comments on commit 805401a

Please sign in to comment.