Skip to content

Commit

Permalink
Merge pull request #49 from leekelleher/wip/itempicker-overlay-close-…
Browse files Browse the repository at this point in the history
…focus

ItemPicker - when overlay is closed, focus state is restored
  • Loading branch information
leekelleher authored Apr 16, 2021
2 parents 429dbad + 805401a commit 7a104c1
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 7a104c1

Please sign in to comment.