-
Notifications
You must be signed in to change notification settings - Fork 885
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* inactive package since 5 years * still requiring React 16.3.x * moving over to already used WP a11y' speak * adding a hook and wrapper component for ease of use, as per downside of original PR: #19615
- Loading branch information
1 parent
02d9de1
commit 40daf80
Showing
9 changed files
with
71 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import PropTypes from "prop-types"; | ||
import { useSpokenMessage } from "../hooks"; | ||
|
||
/** | ||
* Announces the message with the given politeness, if a valid message is provided. | ||
* Wraps the `useSpokenMessage` hook in a component. | ||
* | ||
* @link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions | ||
* @see useSpokenMessage in packages/js/src/settings/hooks/use-spoken-message.js | ||
* | ||
* @param {string} message The message to be announced by assistive technologies. | ||
* @param {?string} [ariaLive] The politeness level for aria-live. Can be "off", "assertive" and anything else defaults to "polite". | ||
* | ||
* @returns {JSX.Element} Null. | ||
*/ | ||
export const SpokenMessage = ( { message, ariaLive } ) => { | ||
useSpokenMessage( message, ariaLive ); | ||
|
||
return null; | ||
}; | ||
|
||
SpokenMessage.propTypes = { | ||
message: PropTypes.string.isRequired, | ||
ariaLive: PropTypes.string, | ||
}; | ||
SpokenMessage.defaultProps = { | ||
// eslint-disable-next-line no-undefined | ||
ariaLive: undefined, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { speak } from "@wordpress/a11y"; | ||
import { renderToString, useEffect, useMemo } from "@wordpress/element"; | ||
import { isString } from "lodash"; | ||
|
||
/** | ||
* Announces the message with the given politeness, if a valid message is provided. | ||
* Taken from the `useSpokenMessage` hook in Gutenberg Snackbar component. | ||
* | ||
* @link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions | ||
* @link https://github.com/WordPress/gutenberg/tree/trunk/packages/a11y | ||
* | ||
* @param {string} message The message to be announced by assistive technologies. | ||
* @param {?string} [ariaLive] The politeness level for aria-live. Can be "off", "assertive" and anything else defaults to "polite". | ||
* | ||
* @returns {void} | ||
*/ | ||
export const useSpokenMessage = ( message, ariaLive ) => { | ||
const spokenMessage = useMemo( () => isString( message ) ? message : renderToString( message ), [ message ] ); | ||
|
||
useEffect( () => { | ||
if ( spokenMessage ) { | ||
speak( spokenMessage, ariaLive ); | ||
} | ||
}, [ spokenMessage, ariaLive ] ); | ||
}; |
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