-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
159 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[ | ||
{ | ||
path: "dist/es2015/index.js", | ||
limit: "2.6 kB" | ||
limit: "2.7 kB" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[ | ||
{ | ||
"name": "dist/es2015/index.js", | ||
"passed": true, | ||
"size": 2653 | ||
"passed": false, | ||
"size": 2726 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,56 @@ | ||
import { filterFocusable } from '../src/utils/DOMutils'; | ||
import { FOCUS_ALLOW, FOCUS_DISABLED, FOCUS_NO_AUTOFOCUS } from '../src/constants'; | ||
import { filterAutoFocusable, getAllTabbableNodes } from '../src/utils/DOMutils'; | ||
|
||
describe('focusables', () => { | ||
it('should remove disabled buttons', () => { | ||
document.body.innerHTML = ` | ||
<button>normal button</button> | ||
<button disabled>disabled button</button> | ||
<button disabled>disabled button (remove)</button> | ||
<button aria-disabled="true">aria-disabled button</button> | ||
<button style="display: none">hidden button</button> | ||
<button style="display: none">hidden button (remove)</button> | ||
`; | ||
|
||
expect( | ||
filterFocusable(Array.from(document.body.querySelectorAll('*')), new Map()).map((el) => el.textContent) | ||
).toEqual([ | ||
const cache = new Map(); | ||
const nodes = getAllTabbableNodes([document.body], cache).map(({ node }) => node); | ||
|
||
expect(nodes.map((el) => el.textContent)).toEqual([ | ||
// because it's normal button | ||
'normal button', | ||
// because it's "marked" as disabled for ARIA only | ||
'aria-disabled button', | ||
]); | ||
}); | ||
}); | ||
|
||
describe('auto-focusables', () => { | ||
it('should pick correct first autofocus', () => { | ||
document.body.innerHTML = ` | ||
<button>normal button</button> | ||
<button disabled>disabled button (remove)</button> | ||
<button aria-disabled="true">aria-disabled button</button> | ||
<button ${FOCUS_NO_AUTOFOCUS}="true">skip autofocus (remove)</button> | ||
<button tabindex="-1">tabindex-1 button</button> | ||
<div ${FOCUS_ALLOW}="true"> | ||
<button>normal button in allow group</button> | ||
</div> | ||
<div ${FOCUS_DISABLED}="true"> | ||
<button>normal button in disabled group</button> | ||
</div> | ||
<div ${FOCUS_NO_AUTOFOCUS}="true"> | ||
<button>normal button in no autofocus group (remove)</button> | ||
</div> | ||
`; | ||
|
||
const cache = new Map(); | ||
const nodes = getAllTabbableNodes([document.body], cache).map(({ node }) => node); | ||
|
||
expect(filterAutoFocusable(nodes).map((el) => el.textContent)).toEqual([ | ||
// hoisted | ||
'tabindex-1 button', | ||
'normal button', | ||
'aria-disabled button', | ||
'normal button in allow group', | ||
'normal button in disabled group', | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,22 @@ | ||
/** | ||
* defines a focus group | ||
*/ | ||
export const FOCUS_GROUP = 'data-focus-lock'; | ||
/** | ||
* disables element discovery inside a group marked by key | ||
*/ | ||
export const FOCUS_DISABLED = 'data-focus-lock-disabled'; | ||
/** | ||
* allows uncontrolled focus within the marked area, effectively disabling focus lock for it's content | ||
*/ | ||
export const FOCUS_ALLOW = 'data-no-focus-lock'; | ||
/** | ||
* instructs autofocus engine to pick default autofocus inside a given node | ||
* can be set on the element or container | ||
*/ | ||
export const FOCUS_AUTO = 'data-autofocus-inside'; | ||
/** | ||
* instructs autofocus to ignore elements within a given node | ||
* can be set on the element or container | ||
*/ | ||
export const FOCUS_NO_AUTOFOCUS = 'data-no-autofocus'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters