-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4414 from ebonow/aria-messages-v4
Aria Live Configuration
- Loading branch information
Showing
14 changed files
with
760 additions
and
363 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,6 @@ | ||
--- | ||
'@react-select/docs': minor | ||
'react-select': minor | ||
--- | ||
|
||
Add ariaLiveMessages prop for internationalization and other customizations |
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,58 @@ | ||
// @flow | ||
import React, { useState } from 'react'; | ||
|
||
import Select from 'react-select'; | ||
import { colourOptions } from '../data'; | ||
|
||
export default function CustomAriaLive() { | ||
const [ariaFocusMessage, setAriaFocusMessage] = useState(''); | ||
const [isMenuOpen, setIsMenuOpen] = useState(false); | ||
|
||
const style = { | ||
blockquote: { | ||
fontStyle: 'italic', | ||
fontSize: '.75rem', | ||
margin: '1rem 0', | ||
}, | ||
label: { | ||
fontSize: '.75rem', | ||
fontWeight: 'bold', | ||
lineHeight: 2, | ||
}, | ||
}; | ||
|
||
const onFocus = ({ focused, isDisabled }) => { | ||
const msg = `You are currently focused on option ${focused.label}${ | ||
isDisabled ? ', disabled' : '' | ||
}`; | ||
setAriaFocusMessage(msg); | ||
return msg; | ||
}; | ||
|
||
const onMenuOpen = () => setIsMenuOpen(true); | ||
const onMenuClose = () => setIsMenuOpen(false); | ||
|
||
return ( | ||
<form> | ||
<label style={style.label} id="aria-label" htmlFor="aria-example-input"> | ||
Select a color | ||
</label> | ||
|
||
{!!ariaFocusMessage && !!isMenuOpen && ( | ||
<blockquote style={style.blockquote}>"{ariaFocusMessage}"</blockquote> | ||
)} | ||
|
||
<Select | ||
aria-labelledby="aria-label" | ||
ariaLiveMessages={{ | ||
onFocus, | ||
}} | ||
inputId="aria-example-input" | ||
name="aria-live-color" | ||
onMenuOpen={onMenuOpen} | ||
onMenuClose={onMenuClose} | ||
options={colourOptions} | ||
/> | ||
</form> | ||
); | ||
} |
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.