Skip to content

Commit f9b2015

Browse files
authored
Merge pull request #4414 from ebonow/aria-messages-v4
Aria Live Configuration
2 parents 711967a + f4aaf24 commit f9b2015

File tree

14 files changed

+760
-363
lines changed

14 files changed

+760
-363
lines changed

.changeset/shaggy-chairs-poke.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@react-select/docs': minor
3+
'react-select': minor
4+
---
5+
6+
Add ariaLiveMessages prop for internationalization and other customizations

docs/examples/CustomAriaLive.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// @flow
2+
import React, { useState } from 'react';
3+
4+
import Select from 'react-select';
5+
import { colourOptions } from '../data';
6+
7+
export default function CustomAriaLive() {
8+
const [ariaFocusMessage, setAriaFocusMessage] = useState('');
9+
const [isMenuOpen, setIsMenuOpen] = useState(false);
10+
11+
const style = {
12+
blockquote: {
13+
fontStyle: 'italic',
14+
fontSize: '.75rem',
15+
margin: '1rem 0',
16+
},
17+
label: {
18+
fontSize: '.75rem',
19+
fontWeight: 'bold',
20+
lineHeight: 2,
21+
},
22+
};
23+
24+
const onFocus = ({ focused, isDisabled }) => {
25+
const msg = `You are currently focused on option ${focused.label}${
26+
isDisabled ? ', disabled' : ''
27+
}`;
28+
setAriaFocusMessage(msg);
29+
return msg;
30+
};
31+
32+
const onMenuOpen = () => setIsMenuOpen(true);
33+
const onMenuClose = () => setIsMenuOpen(false);
34+
35+
return (
36+
<form>
37+
<label style={style.label} id="aria-label" htmlFor="aria-example-input">
38+
Select a color
39+
</label>
40+
41+
{!!ariaFocusMessage && !!isMenuOpen && (
42+
<blockquote style={style.blockquote}>"{ariaFocusMessage}"</blockquote>
43+
)}
44+
45+
<Select
46+
aria-labelledby="aria-label"
47+
ariaLiveMessages={{
48+
onFocus,
49+
}}
50+
inputId="aria-example-input"
51+
name="aria-live-color"
52+
onMenuOpen={onMenuOpen}
53+
onMenuClose={onMenuClose}
54+
options={colourOptions}
55+
/>
56+
</form>
57+
);
58+
}

docs/examples/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export { default as AsyncPromises } from './AsyncPromises';
77
export { default as BasicGrouped } from './BasicGrouped';
88
export { default as BasicMulti } from './BasicMulti';
99
export { default as BasicSingle } from './BasicSingle';
10+
export { default as CustomAriaLive } from './CustomAriaLive';
1011
export { default as CustomControl } from './CustomControl';
1112
export { default as CreatableAdvanced } from './CreatableAdvanced';
1213
export { default as CreatableInputOnly } from './CreatableInputOnly';

docs/pages/advanced/index.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ import md from '../../markdown/renderer';
55
import ExampleWrapper from '../../ExampleWrapper';
66
import {
77
AccessingInternals,
8-
ControlledMenu,
9-
OnSelectResetsInput,
108
BasicGrouped,
119
CreateFilter,
10+
ControlledMenu,
11+
CustomAriaLive,
1212
CustomFilterOptions,
1313
CustomGetOptionLabel,
1414
CustomGetOptionValue,
1515
CustomIsOptionDisabled,
1616
Experimental,
17-
Popout,
1817
MenuBuffer,
1918
MenuPortal,
2019
MultiSelectSort,
20+
Popout,
21+
OnSelectResetsInput,
2122
} from '../../examples';
2223

2324
export default function Advanced() {
@@ -33,6 +34,20 @@ export default function Advanced() {
3334
{md`
3435
# Advanced
3536
37+
## Accessibility
38+
Accessibility is important. React-select is committed to providing a custom experience to all users and relies heavily on the aria-live spec to provide
39+
a custom experience for all users. As such, we also provide an api to address internationalization or further customization.
40+
41+
${(
42+
<ExampleWrapper
43+
label="Custom aria live example"
44+
urlPath="docs/examples/CustomAriaLive.js"
45+
raw={require('!!raw-loader!../../examples/CustomAriaLive.js')}
46+
>
47+
<CustomAriaLive />
48+
</ExampleWrapper>
49+
)}
50+
3651
## Sortable MultiSelect
3752
Using the [react-sortable-hoc](https://www.npmjs.com/package/react-sortable-hoc) package we can easily allow sorting of MultiSelect values by drag and drop.
3853

0 commit comments

Comments
 (0)