forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shortcut aria label for unreadable shortcuts (WordPress#9582)
* Add new utility function that returns an aria label describing the shortcut * Add Shortcut component * Use new Shortcut component in MenuItem and Tooltip components * Add aria-label for toggleSidebar shortcut to ensure comma is read by screenreaders * On Apple systems do not separate keys in shortcut aria label by +, this matches how shortcut is rendered * Improve naming in keycodes package * Remove unused class name * Add aria labels for shortcuts in keyboard shortcut help modal * Fix copy typo
- Loading branch information
1 parent
4c579ed
commit 6712e28
Showing
16 changed files
with
197 additions
and
36 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
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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { isString, isObject } from 'lodash'; | ||
|
||
function Shortcut( { shortcut, className } ) { | ||
if ( ! shortcut ) { | ||
return null; | ||
} | ||
|
||
let displayText; | ||
let ariaLabel; | ||
|
||
if ( isString( shortcut ) ) { | ||
displayText = shortcut; | ||
} | ||
|
||
if ( isObject( shortcut ) ) { | ||
displayText = shortcut.display; | ||
ariaLabel = shortcut.ariaLabel; | ||
} | ||
|
||
return ( | ||
<span className={ className } aria-label={ ariaLabel }> | ||
{ displayText } | ||
</span> | ||
); | ||
} | ||
|
||
export default Shortcut; |
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,41 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Shortcut from '../'; | ||
|
||
describe( 'Shortcut', () => { | ||
it( 'does not render anything if no shortcut prop is provided', () => { | ||
const wrapper = shallow( <Shortcut /> ); | ||
|
||
expect( wrapper.children() ).toHaveLength( 0 ); | ||
} ); | ||
|
||
it( 'renders the shortcut display text when a string is passed as the shortcut', () => { | ||
const wrapper = shallow( | ||
<Shortcut | ||
shortcut="shortcut text" | ||
/> | ||
); | ||
|
||
expect( wrapper.text() ).toBe( 'shortcut text' ); | ||
} ); | ||
|
||
it( 'renders the shortcut display text and aria-label when an object is passed as the shortcut with the correct properties', () => { | ||
const wrapper = shallow( | ||
<Shortcut | ||
shortcut={ { | ||
display: 'shortcut text', | ||
ariaLabel: 'shortcut label', | ||
} } | ||
/> | ||
); | ||
|
||
expect( wrapper.text() ).toBe( 'shortcut text' ); | ||
expect( wrapper.prop( 'aria-label' ) ).toBe( 'shortcut label' ); | ||
} ); | ||
} ); |
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
Oops, something went wrong.