mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 03:26:36 +00:00
change selector criteria for tabbable elements based on react component logic
This commit is contained in:
parent
48a5d16335
commit
c9b2f5402c
1 changed files with 10 additions and 2 deletions
|
@ -144,8 +144,16 @@
|
|||
open = false;
|
||||
} else if (e.key === 'Tab') {
|
||||
// trap focus
|
||||
const nodes = ref.querySelectorAll('*');
|
||||
const tabbable = Array.from(nodes).filter((n) => n.tabIndex >= 0);
|
||||
|
||||
// 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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue