-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(a11y): lose focus after activating share button
- Loading branch information
1 parent
fa8c142
commit 1cd135e
Showing
2 changed files
with
30 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { copyToClipboard } from './clipboard'; | ||
|
||
document.execCommand = vi.fn(); | ||
const execCommandMocked = vi.mocked(document.execCommand); | ||
|
||
describe('clipboard', () => { | ||
test('copies text to clipboard', () => { | ||
copyToClipboard('text to copy'); | ||
|
||
expect(execCommandMocked).toHaveBeenCalledWith('copy'); | ||
}); | ||
|
||
test('restores focus to the last active element', () => { | ||
// create a test button | ||
const button = document.createElement('button'); | ||
button.textContent = 'share'; | ||
|
||
document.body.appendChild(button); | ||
|
||
button.focus(); | ||
|
||
// document.activeElement = ''; | ||
copyToClipboard('text to copy'); | ||
|
||
expect(document.activeElement).toEqual(button); | ||
document.body.removeChild(button); | ||
}); | ||
}); |
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