bug fixes
This commit is contained in:
parent
b4838a5076
commit
583a14d1ad
34
components/dist/popup.js
vendored
34
components/dist/popup.js
vendored
@ -424,14 +424,28 @@ customElements.define('sm-popup', class extends HTMLElement {
|
|||||||
|
|
||||||
detectFocus(e) {
|
detectFocus(e) {
|
||||||
if (e.key === 'Tab') {
|
if (e.key === 'Tab') {
|
||||||
const lastElement = this.focusable[this.focusable.length - 1];
|
// go through the focusable list and find the first and last element that is not disabled
|
||||||
const firstElement = this.focusable[0];
|
if (!this.focusable.length) return;
|
||||||
if (e.shiftKey && document.activeElement === firstElement) {
|
if (!this.firstFocusable)
|
||||||
|
for (let i = 0; i < this.focusable.length; i++) {
|
||||||
|
if (!this.focusable[i].disabled) {
|
||||||
|
this.firstFocusable = this.focusable[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.lastFocusable)
|
||||||
|
for (let i = this.focusable.length - 1; i >= 0; i--) {
|
||||||
|
if (!this.focusable[i].disabled) {
|
||||||
|
this.lastFocusable = this.focusable[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.shiftKey && document.activeElement === this.firstFocusable) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
lastElement.tagName.includes('SM-') ? lastElement.focusIn() : lastElement.focus();
|
this.lastFocusable.tagName.includes('SM-') ? this.lastFocusable.focusIn() : this.lastFocusable.focus();
|
||||||
} else if (!e.shiftKey && document.activeElement === lastElement) {
|
} else if (!e.shiftKey && document.activeElement === this.lastFocusable) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
firstElement.tagName.includes('SM-') ? firstElement.focusIn() : firstElement.focus();
|
this.firstFocusable.tagName.includes('SM-') ? this.firstFocusable.focusIn() : this.firstFocusable.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -439,6 +453,8 @@ customElements.define('sm-popup', class extends HTMLElement {
|
|||||||
updateFocusableList() {
|
updateFocusableList() {
|
||||||
this.focusable = this.querySelectorAll('sm-button:not([disabled]), button:not([disabled]), [href], sm-input, input:not([readonly]), sm-select, select, sm-checkbox, sm-textarea, textarea, [tabindex]:not([tabindex="-1"])')
|
this.focusable = this.querySelectorAll('sm-button:not([disabled]), button:not([disabled]), [href], sm-input, input:not([readonly]), sm-select, select, sm-checkbox, sm-textarea, textarea, [tabindex]:not([tabindex="-1"])')
|
||||||
this.autoFocus = this.querySelector('[autofocus]')
|
this.autoFocus = this.querySelector('[autofocus]')
|
||||||
|
this.firstFocusable = null
|
||||||
|
this.lastFocusable = null
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSoftDismiss() {
|
handleSoftDismiss() {
|
||||||
@ -468,12 +484,12 @@ customElements.define('sm-popup', class extends HTMLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
this.popupBodySlot.addEventListener('slotchange', this.debounce(() => {
|
this.popupBodySlot.addEventListener('slotchange', debounce(() => {
|
||||||
this.forms = this.querySelectorAll('sm-form');
|
this.forms = this.querySelectorAll('sm-form');
|
||||||
this.updateFocusableList()
|
this.updateFocusableList()
|
||||||
}, 0));
|
}, 0));
|
||||||
this.resizeObserver = new ResizeObserver(entries => {
|
this.resizeObserver = new ResizeObserver(entries => {
|
||||||
for (let entry of entries) {
|
entries.forEach(entry => {
|
||||||
if (entry.contentBoxSize) {
|
if (entry.contentBoxSize) {
|
||||||
// Firefox implements `contentBoxSize` as a single content rect, rather than an array
|
// Firefox implements `contentBoxSize` as a single content rect, rather than an array
|
||||||
const contentBoxSize = Array.isArray(entry.contentBoxSize) ? entry.contentBoxSize[0] : entry.contentBoxSize;
|
const contentBoxSize = Array.isArray(entry.contentBoxSize) ? entry.contentBoxSize[0] : entry.contentBoxSize;
|
||||||
@ -481,7 +497,7 @@ customElements.define('sm-popup', class extends HTMLElement {
|
|||||||
} else {
|
} else {
|
||||||
this.threshold = entry.contentRect.height * 0.3;
|
this.threshold = entry.contentRect.height * 0.3;
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
this.mutationObserver = new MutationObserver(entries => {
|
this.mutationObserver = new MutationObserver(entries => {
|
||||||
|
|||||||
2
components/dist/popup.min.js
vendored
2
components/dist/popup.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user