Skip to content

Commit

Permalink
Fix findNearestDialog for child of slotted element
Browse files Browse the repository at this point in the history
A focus event for an element which is a child of a slotted element
will be erroneously reported as not in the topmost dialog. This is
because for the slotted element we should follow assignedSlot rather
than the parentElement or parentNode to get the true hierarchy in
which the elmeent lives. This change adds handling for slotted
elements.
  • Loading branch information
carmour24 committed Jul 22, 2021
1 parent 5033aac commit cb1db45
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion dist/dialog-polyfill.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ function findNearestDialog(el) {
if (el.localName === 'dialog') {
return /** @type {HTMLDialogElement} */ (el);
}
if (el.parentElement) {
if (el.assignedSlot) {
el = el.assignedSlot;
} else if (el.parentElement) {
el = el.parentElement;
} else if (el.parentNode) {
el = el.parentNode.host;
Expand Down
4 changes: 3 additions & 1 deletion dist/dialog-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
if (el.localName === 'dialog') {
return /** @type {HTMLDialogElement} */ (el);
}
if (el.parentElement) {
if (el.assignedSlot) {
el = el.assignedSlot;
} else if (el.parentElement) {
el = el.parentElement;
} else if (el.parentNode) {
el = el.parentNode.host;
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ function findNearestDialog(el) {
if (el.localName === 'dialog') {
return /** @type {HTMLDialogElement} */ (el);
}
if (el.parentElement) {
if (el.assignedSlot) {
el = el.assignedSlot;
} else if (el.parentElement) {
el = el.parentElement;
} else if (el.parentNode) {
el = el.parentNode.host;
Expand Down

0 comments on commit cb1db45

Please sign in to comment.