performance improvements
This commit is contained in:
parent
3c885f92c7
commit
31541982b2
38
components/dist/popup.js
vendored
38
components/dist/popup.js
vendored
@ -279,20 +279,23 @@ customElements.define('sm-popup', class extends HTMLElement {
|
|||||||
this.backdrop.animate([
|
this.backdrop.animate([
|
||||||
{ opacity: 0 },
|
{ opacity: 0 },
|
||||||
{ opacity: 1 },
|
{ opacity: 1 },
|
||||||
], animOptions)
|
], animOptions).onfinish = () => {
|
||||||
|
this.dispatchEvent(
|
||||||
|
new CustomEvent("popupopened", {
|
||||||
|
bubbles: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
document.body.style.overflow = 'hidden';
|
||||||
|
document.body.style.top = `-${window.scrollY}px`;
|
||||||
|
}
|
||||||
this.setStateOpen()
|
this.setStateOpen()
|
||||||
this.dispatchEvent(
|
|
||||||
new CustomEvent("popupopened", {
|
|
||||||
bubbles: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
this.pinned = pinned;
|
this.pinned = pinned;
|
||||||
this.isOpen = true;
|
this.isOpen = true;
|
||||||
document.body.style.overflow = 'hidden';
|
setTimeout(() => {
|
||||||
document.body.style.top = `-${window.scrollY}px`;
|
const elementToFocus = this.autoFocus || this.focusable?.[0] || this.dialogBox;
|
||||||
const elementToFocus = this.autoFocus || this.focusable[0];
|
if (elementToFocus)
|
||||||
if (elementToFocus)
|
elementToFocus.tagName.includes('-') ? elementToFocus.focusIn() : elementToFocus.focus();
|
||||||
elementToFocus.tagName.includes('SM-') ? elementToFocus.focusIn() : elementToFocus.focus();
|
}, 0);
|
||||||
if (!this.hasAttribute('open')) {
|
if (!this.hasAttribute('open')) {
|
||||||
this.setAttribute('open', '');
|
this.setAttribute('open', '');
|
||||||
this.addEventListener('keydown', this.detectFocus);
|
this.addEventListener('keydown', this.detectFocus);
|
||||||
@ -436,12 +439,21 @@ customElements.define('sm-popup', class extends HTMLElement {
|
|||||||
this.hide();
|
this.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
debounce(callback, wait) {
|
||||||
|
let timeoutId = null;
|
||||||
|
return (...args) => {
|
||||||
|
window.clearTimeout(timeoutId);
|
||||||
|
timeoutId = window.setTimeout(() => {
|
||||||
|
callback.apply(null, args);
|
||||||
|
}, wait);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
this.popupBodySlot.addEventListener('slotchange', () => {
|
this.popupBodySlot.addEventListener('slotchange', this.debounce(() => {
|
||||||
this.forms = this.querySelectorAll('sm-form');
|
this.forms = this.querySelectorAll('sm-form');
|
||||||
this.updateFocusableList()
|
this.updateFocusableList()
|
||||||
});
|
}, 0));
|
||||||
this.resizeObserver = new ResizeObserver(entries => {
|
this.resizeObserver = new ResizeObserver(entries => {
|
||||||
for (let entry of entries) {
|
for (let entry of entries) {
|
||||||
if (entry.contentBoxSize) {
|
if (entry.contentBoxSize) {
|
||||||
|
|||||||
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
@ -34,15 +34,29 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<collapsed-text>
|
<button>Show popup</button>
|
||||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Architecto minima maiores autem iusto porro, odit iure
|
<sm-popup>
|
||||||
ea eveniet enim soluta ex a nihil? Dicta ducimus dolor itaque unde sequi, reprehenderit ex aperiam dignissimos
|
<input type="text" placeholder="fds">
|
||||||
inventore? Totam aliquid repellendus nulla culpa nemo perspiciatis tempora. Vel obcaecati asperiores nam,
|
<button>dsfsd</button>
|
||||||
ratione sint itaque temporibus incidunt officiis iusto cumque reiciendis ab repellendus quaerat ducimus
|
<collapsed-text>
|
||||||
quibusdam quia maxime nostrum atque ad sequi eveniet est error ipsam voluptatem. Architecto molestiae ex et
|
Lorem ipsum dolor sit amet consectetur adipisicing elit. Architecto minima maiores autem iusto porro, odit
|
||||||
minima praesentium quasi ea, ad enim consequuntur at nisi nostrum. Quisquam nostrum, accusamus neque, fugiat
|
iure
|
||||||
esse deleniti ex vitae totam asperiores odit quaerat sunt voluptates.
|
ea eveniet enim soluta ex a nihil? Dicta ducimus dolor itaque unde sequi, reprehenderit ex aperiam
|
||||||
</collapsed-text>
|
dignissimos
|
||||||
|
inventore? Totam aliquid repellendus nulla culpa nemo perspiciatis tempora. Vel obcaecati asperiores nam,
|
||||||
|
ratione sint itaque temporibus incidunt officiis iusto cumque reiciendis ab repellendus quaerat ducimus
|
||||||
|
quibusdam quia maxime nostrum atque ad sequi eveniet est error ipsam voluptatem. Architecto molestiae ex et
|
||||||
|
minima praesentium quasi ea, ad enim consequuntur at nisi nostrum. Quisquam nostrum, accusamus neque, fugiat
|
||||||
|
esse deleniti ex vitae totam asperiores odit quaerat sunt voluptates.
|
||||||
|
</collapsed-text>
|
||||||
|
</sm-popup>
|
||||||
</body>
|
</body>
|
||||||
|
<script>
|
||||||
|
const popup = document.querySelector('sm-popup');
|
||||||
|
popup.show();
|
||||||
|
document.querySelector('button').addEventListener('click', () => {
|
||||||
|
popup.show();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user