Merge branch 'master' into recursive-list

This commit is contained in:
Eric Liu 2021-07-05 08:43:23 -07:00 committed by GitHub
commit 5c4f9a50f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 93 additions and 14 deletions

View file

@ -103,6 +103,33 @@
class:is-visible="{open}"
class:bx--modal--danger="{danger}"
{...$$restProps}
on:keydown
on:keydown="{(e) => {
if (open) {
if (e.key === 'Escape') {
open = false;
} else if (e.key === 'Tab') {
// taken from github.com/carbon-design-system/carbon/packages/react/src/internal/keyboard/navigation.js
const selectorTabbable = `
a[href], area[href], input:not([disabled]):not([tabindex='-1']),
button:not([disabled]):not([tabindex='-1']),select:not([disabled]):not([tabindex='-1']),
textarea:not([disabled]):not([tabindex='-1']),
iframe, object, embed, *[tabindex]:not([tabindex='-1']):not([disabled]), *[contenteditable=true]
`;
const tabbable = Array.from(ref.querySelectorAll(selectorTabbable));
let index = tabbable.indexOf(document.activeElement);
if (index === -1 && e.shiftKey) index = 0;
index += tabbable.length + (e.shiftKey ? -1 : 1);
index %= tabbable.length;
tabbable[index].focus();
e.preventDefault();
}
}
}}"
on:click
on:click="{() => {
if (!didClickInnerModal && !preventCloseOnClickOutside) open = false;

View file

@ -138,11 +138,32 @@
class:bx--modal--danger="{danger}"
{...$$restProps}
on:keydown
on:keydown="{({ key }) => {
on:keydown="{(e) => {
if (open) {
if (key === 'Escape') {
if (e.key === 'Escape') {
open = false;
} else if (shouldSubmitOnEnter && key === 'Enter') {
} else if (e.key === 'Tab') {
// trap focus
// taken from github.com/carbon-design-system/carbon/packages/react/src/internal/keyboard/navigation.js
const selectorTabbable = `
a[href], area[href], input:not([disabled]):not([tabindex='-1']),
button:not([disabled]):not([tabindex='-1']),select:not([disabled]):not([tabindex='-1']),
textarea:not([disabled]):not([tabindex='-1']),
iframe, object, embed, *[tabindex]:not([tabindex='-1']):not([disabled]), *[contenteditable=true]
`;
const tabbable = Array.from(ref.querySelectorAll(selectorTabbable));
let index = tabbable.indexOf(document.activeElement);
if (index === -1 && e.shiftKey) index = 0;
index += tabbable.length + (e.shiftKey ? -1 : 1);
index %= tabbable.length;
tabbable[index].focus();
e.preventDefault();
} else if (shouldSubmitOnEnter && e.key === 'Enter') {
dispatch('submit');
}
}

View file

@ -36,7 +36,7 @@
add({ id, text, primaryFocus });
afterUpdate(() => {
if (primaryFocus) {
if (ref && primaryFocus) {
ref.focus();
}
});

View file

@ -90,6 +90,7 @@
class:bx--text-area--light="{light}"
class:bx--text-area--invalid="{invalid}"
{...$$restProps}
readonly="{$$restProps.readonly === true ? true : undefined}"
on:change
on:input
on:input="{({ target }) => {