kopia lustrzana https://github.com/shoelace-style/shoelace
Fix transitions in Safari
rodzic
d3e378506e
commit
3fd2ab1991
|
@ -132,7 +132,7 @@ By default, the dialog's panel will gain focus when opened. To set focus on a di
|
||||||
|
|
||||||
dialog.addEventListener('sl-initial-focus', event => {
|
dialog.addEventListener('sl-initial-focus', event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
input.setFocus()
|
input.setFocus({ preventScroll: true });
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -227,10 +227,8 @@ By default, the drawer's panel will gain focus when opened. To set focus on a di
|
||||||
closeButton.addEventListener('click', () => drawer.hide());
|
closeButton.addEventListener('click', () => drawer.hide());
|
||||||
|
|
||||||
drawer.addEventListener('sl-initial-focus', event => {
|
drawer.addEventListener('sl-initial-focus', event => {
|
||||||
// preventScroll is necessary for the transition to work properly,
|
|
||||||
// otherwise the drawer will appear immediately
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
input.setFocus({ preventScroll: true })
|
input.setFocus({ preventScroll: true });
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import { Component, Element, Event, EventEmitter, Method, Prop, State, Watch, h } from '@stencil/core';
|
import { Component, Element, Event, EventEmitter, Method, Prop, State, Watch, h } from '@stencil/core';
|
||||||
import { lockBodyScrolling, unlockBodyScrolling } from '../../utilities/scroll';
|
import { lockBodyScrolling, unlockBodyScrolling } from '../../utilities/scroll';
|
||||||
import { hasSlot } from '../../utilities/slot';
|
import { hasSlot } from '../../utilities/slot';
|
||||||
|
import { isPreventScrollSupported } from '../../utilities/support';
|
||||||
import Modal from '../../utilities/modal';
|
import Modal from '../../utilities/modal';
|
||||||
|
|
||||||
|
const hasPreventScroll = isPreventScrollSupported();
|
||||||
|
|
||||||
let id = 0;
|
let id = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,13 +131,29 @@ export class Dialog {
|
||||||
lockBodyScrolling(this.host);
|
lockBodyScrolling(this.host);
|
||||||
|
|
||||||
if (this.open) {
|
if (this.open) {
|
||||||
// Wait for the next frame before setting initial focus so the dialog is technically visible
|
if (hasPreventScroll) {
|
||||||
requestAnimationFrame(() => {
|
// Wait for the next frame before setting initial focus so the dialog is technically visible
|
||||||
const slInitialFocus = this.slInitialFocus.emit();
|
requestAnimationFrame(() => {
|
||||||
if (!slInitialFocus.defaultPrevented) {
|
const slInitialFocus = this.slInitialFocus.emit();
|
||||||
this.panel.focus({ preventScroll: true });
|
if (!slInitialFocus.defaultPrevented) {
|
||||||
}
|
this.panel.focus({ preventScroll: true });
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Once Safari supports { preventScroll: true } we can remove this nasty little hack, but until then we need to
|
||||||
|
// wait for the transition to complete before setting focus, otherwise the panel may render in a buggy way its
|
||||||
|
// out of view initially.
|
||||||
|
//
|
||||||
|
// Fiddle: https://jsfiddle.net/g6buoafq/1/
|
||||||
|
// Safari: https://bugs.webkit.org/show_bug.cgi?id=178583
|
||||||
|
//
|
||||||
|
setTimeout(() => {
|
||||||
|
const slInitialFocus = this.slInitialFocus.emit();
|
||||||
|
if (!slInitialFocus.defaultPrevented) {
|
||||||
|
this.panel.focus();
|
||||||
|
}
|
||||||
|
}, 250);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import { Component, Element, Event, EventEmitter, Method, Prop, State, Watch, h } from '@stencil/core';
|
import { Component, Element, Event, EventEmitter, Method, Prop, State, Watch, h } from '@stencil/core';
|
||||||
import { lockBodyScrolling, unlockBodyScrolling } from '../../utilities/scroll';
|
import { lockBodyScrolling, unlockBodyScrolling } from '../../utilities/scroll';
|
||||||
import { hasSlot } from '../../utilities/slot';
|
import { hasSlot } from '../../utilities/slot';
|
||||||
|
import { isPreventScrollSupported } from '../../utilities/support';
|
||||||
import Modal from '../../utilities/modal';
|
import Modal from '../../utilities/modal';
|
||||||
|
|
||||||
|
const hasPreventScroll = isPreventScrollSupported();
|
||||||
|
|
||||||
let id = 0;
|
let id = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,13 +142,29 @@ export class Drawer {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.open) {
|
if (this.open) {
|
||||||
// Wait for the next frame before setting initial focus so the drawer is technically visible
|
if (hasPreventScroll) {
|
||||||
requestAnimationFrame(() => {
|
// Wait for the next frame before setting initial focus so the dialog is technically visible
|
||||||
const slInitialFocus = this.slInitialFocus.emit();
|
requestAnimationFrame(() => {
|
||||||
if (!slInitialFocus.defaultPrevented) {
|
const slInitialFocus = this.slInitialFocus.emit();
|
||||||
this.panel.focus({ preventScroll: true });
|
if (!slInitialFocus.defaultPrevented) {
|
||||||
}
|
this.panel.focus({ preventScroll: true });
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Once Safari supports { preventScroll: true } we can remove this nasty little hack, but until then we need to
|
||||||
|
// wait for the transition to complete before setting focus, otherwise the panel may render in a buggy way its
|
||||||
|
// out of view initially.
|
||||||
|
//
|
||||||
|
// Fiddle: https://jsfiddle.net/g6buoafq/1/
|
||||||
|
// Safari: https://bugs.webkit.org/show_bug.cgi?id=178583
|
||||||
|
//
|
||||||
|
setTimeout(() => {
|
||||||
|
const slInitialFocus = this.slInitialFocus.emit();
|
||||||
|
if (!slInitialFocus.defaultPrevented) {
|
||||||
|
this.panel.focus();
|
||||||
|
}
|
||||||
|
}, 250);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue