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 Oct 25, 2020
1 parent 5542b4e commit 4527f87
Showing 1 changed file with 22 additions and 5 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 @@ -76,6 +77,8 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.

function add() {

focusService.rememberFocus();

var items = Object.toBoolean(config.allowDuplicates) ? config.items : _.reject(config.items, function (x) { // TODO: Replace Underscore.js dependency. [LK:2020-03-02]
return _.find(vm.items, function (y) { return x.name === y.name; }); // TODO: Replace Underscore.js dependency. [LK:2020-03-02]
});
Expand Down Expand Up @@ -103,17 +106,21 @@ 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();

var keys = ["content_nestedContentDeleteItem", "general_delete", "general_cancel", "contentTypeEditor_yesDelete"];
localizationService.localizeMany(keys).then(function (data) {
overlayService.open({
Expand All @@ -131,12 +138,15 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
vm.allowAdd = true;
}

setDirty();

overlayService.close();

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

setFocus();
}
});
});
Expand All @@ -148,6 +158,13 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
}
};

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

init();
}
]);

0 comments on commit 4527f87

Please sign in to comment.