mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
refactor(composed-modal): focus currentTarget in transitionend event
- Dispatch open event
This commit is contained in:
parent
25cd26af24
commit
5e522c399c
1 changed files with 7 additions and 13 deletions
|
@ -30,19 +30,15 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: reuse in Modal
|
||||||
function focus(element) {
|
function focus(element) {
|
||||||
if (element.querySelector(selectorPrimaryFocus)) {
|
const node = (element || innerModal).querySelector(selectorPrimaryFocus) || buttonRef;
|
||||||
return focusElement.focus();
|
node.focus();
|
||||||
}
|
|
||||||
|
|
||||||
if (buttonRef) {
|
|
||||||
buttonRef.focus();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await tick();
|
await tick();
|
||||||
focus(innerModal);
|
focus();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
document.body.classList.remove(cx('--body--with-modal-open'));
|
document.body.classList.remove(cx('--body--with-modal-open'));
|
||||||
|
@ -50,11 +46,8 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
if (!didOpen) {
|
|
||||||
focus(outerModal);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (open) {
|
if (open) {
|
||||||
|
dispatch('open');
|
||||||
document.body.classList.add(cx('--body--with-modal-open'));
|
document.body.classList.add(cx('--body--with-modal-open'));
|
||||||
} else {
|
} else {
|
||||||
dispatch('close');
|
dispatch('close');
|
||||||
|
@ -80,8 +73,9 @@
|
||||||
on:mouseenter
|
on:mouseenter
|
||||||
on:mouseleave
|
on:mouseleave
|
||||||
on:transitionend
|
on:transitionend
|
||||||
on:transitionend={() => {
|
on:transitionend={({ currentTarget }) => {
|
||||||
if (didOpen) {
|
if (didOpen) {
|
||||||
|
focus(currentTarget);
|
||||||
didOpen = false;
|
didOpen = false;
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue