-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ButtonBase] Update focusVisible polyfill for shadowRoots (#13447)
The focusVisible polyfill for ButtonBase components was not resolving targets inside a shadowRoot. Now the activeElement for nested shadowRoots is resolved to add focus visible classes to targets in the shadow DOM. Closes #13447
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -263,6 +263,51 @@ describe('<ButtonBase />', () => { | |
}); | ||
}); | ||
|
||
describe('focus inside shadowRoot', () => { | ||
let wrapper; | ||
let instance; | ||
let button; | ||
let clock; | ||
|
||
beforeEach(() => { | ||
clock = useFakeTimers(); | ||
const rootElement = document.createElement('div'); | ||
rootElement.tabIndex = 0; | ||
rootElement.attachShadow({ mode: 'open' }); | ||
wrapper = mount( | ||
<ButtonBaseNaked theme={{}} classes={{}} id="test-button"> | ||
Hello | ||
</ButtonBaseNaked>, | ||
); | ||
instance = wrapper.instance(); | ||
button = document.getElementById('test-button'); | ||
if (!button) { | ||
throw new Error('missing button'); | ||
} | ||
|
||
wrapper.simulate('focus'); | ||
rootElement.focus(); | ||
|
||
// Mock activeElement value in shadow root due to lack of support in [email protected] | ||
// https://github.com/jsdom/jsdom/issues/2343 | ||
rootElement.shadowRoot.activeElement = button; | ||
|
||
const event = new window.Event('keyup'); | ||
event.which = keycode('tab'); | ||
window.dispatchEvent(event); | ||
}); | ||
|
||
afterEach(() => { | ||
clock.restore(); | ||
}); | ||
|
||
it('should set focus state for shadowRoot children', () => { | ||
assert.strictEqual(wrapper.state().focusVisible, false); | ||
clock.tick(instance.focusVisibleCheckTime * instance.focusVisibleMaxCheckTimes); | ||
assert.strictEqual(wrapper.state().focusVisible, true); | ||
}); | ||
}); | ||
|
||
describe('mounted tab press listener', () => { | ||
let wrapper; | ||
let instance; | ||
|
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