Skip to content

Commit e4c9fa7

Browse files
committed
Replace react-aria-live with @react-aria/live-announcer
1 parent 2c2f553 commit e4c9fa7

6 files changed

Lines changed: 41 additions & 51 deletions

File tree

__tests__/src/components/SearchHit.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ describe('SearchHit', () => {
8282
wrapper.setProps({ selected: true });
8383
expect(announcer).toHaveBeenCalledWith(
8484
'pagination The Canvas Label The Annotation Label Light up the moose , and start the chai',
85+
'polite',
8586
);
8687
});
8788

__tests__/src/components/SearchResults.test.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,16 @@ describe('SearchResults', () => {
3030
it('renders a SearchHit for each hit', () => {
3131
const selectContentSearchAnnotation = jest.fn();
3232
const wrapper = createWrapper({ selectContentSearchAnnotation });
33-
const searchHits = wrapper.find('LiveMessenger').props().children({});
34-
33+
const searchHits = wrapper.find('Connect(WithStyles(WithPlugins(SearchHit)))');
3534
expect(searchHits.length).toEqual(1);
36-
expect(searchHits[0].type.displayName).toEqual('Connect(WithStyles(WithPlugins(SearchHit)))');
37-
expect(searchHits[0].props.index).toEqual(0);
35+
expect(searchHits.first().props().index).toEqual(0);
3836
});
3937

4038
it('can focus on a single item', () => {
4139
const wrapper = createWrapper({});
42-
const searchHits = wrapper.find('LiveMessenger').props().children({});
40+
const searchHits = wrapper.find('Connect(WithStyles(WithPlugins(SearchHit)))');
4341

44-
searchHits[0].props.showDetails();
42+
searchHits.first().props().showDetails();
4543
expect(wrapper.state().focused).toEqual(true);
4644
});
4745

@@ -54,28 +52,20 @@ describe('SearchResults', () => {
5452
expect(wrapper.state().focused).toEqual(false);
5553
});
5654

57-
it('passes announcePolite function to the SearchHits', () => {
58-
const announcePolite = jest.fn();
59-
const wrapper = createWrapper({});
60-
const searchHits = wrapper.find('LiveMessenger').props().children({ announcePolite });
61-
62-
expect(searchHits[0].props.announcer).toEqual(announcePolite);
63-
});
64-
6555
describe('annotation-only search results', () => {
6656
it('renders a SearchHit for each annotation', () => {
6757
const wrapper = createWrapper({
6858
searchAnnotations: [{ id: 'x' }, { id: 'y' }],
6959
searchHits: [],
7060
});
7161

72-
const searchHits = wrapper.find('LiveMessenger').props().children({});
62+
const searchHits = wrapper.find('Connect(WithStyles(WithPlugins(SearchHit)))');
7363
expect(searchHits.length).toEqual(2);
74-
expect(searchHits[0].props.index).toEqual(0);
75-
expect(searchHits[0].props.annotationId).toEqual('x');
64+
expect(searchHits.get(0).props.index).toEqual(0);
65+
expect(searchHits.get(0).props.annotationId).toEqual('x');
7666

77-
expect(searchHits[1].props.index).toEqual(1);
78-
expect(searchHits[1].props.annotationId).toEqual('y');
67+
expect(searchHits.get(1).props.index).toEqual(1);
68+
expect(searchHits.get(1).props.annotationId).toEqual('y');
7969
});
8070
});
8171

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@material-ui/core": "^4.12.3",
3838
"@material-ui/icons": "^4.9.1",
3939
"@material-ui/lab": "^4.0.0-alpha.53",
40+
"@react-aria/live-announcer": "^3.1.2",
4041
"classnames": "^2.2.6",
4142
"clsx": "^1.0.4",
4243
"deepmerge": "^4.2.2",
@@ -50,7 +51,6 @@
5051
"openseadragon": "^2.4.2 || ^3.0.0 || ^4.0.0",
5152
"prop-types": "^15.6.2",
5253
"re-reselect": "^4.0.0",
53-
"react-aria-live": "^2.0.5",
5454
"react-copy-to-clipboard": "^5.0.1",
5555
"react-dnd": "^10.0.2",
5656
"react-dnd-html5-backend": "^10.0.2",

src/components/AppProviders.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import { FullScreen, useFullScreenHandle } from 'react-full-screen';
44
import { I18nextProvider } from 'react-i18next';
5-
import { LiveAnnouncer } from 'react-aria-live';
65
import {
76
ThemeProvider, StylesProvider, createTheme, jssPreset, createGenerateClassName,
87
} from '@material-ui/core/styles';
@@ -115,20 +114,18 @@ export class AppProviders extends Component {
115114
return (
116115
<FullScreenShim>
117116
<I18nextProvider i18n={this.i18n}>
118-
<LiveAnnouncer>
119-
<ThemeProvider
120-
theme={createTheme(theme)}
117+
<ThemeProvider
118+
theme={createTheme(theme)}
119+
>
120+
<StylesProvider
121+
jss={create({ plugins: [...jssPreset().plugins, rtl()] })}
122+
generateClassName={generateClassName}
121123
>
122-
<StylesProvider
123-
jss={create({ plugins: [...jssPreset().plugins, rtl()] })}
124-
generateClassName={generateClassName}
125-
>
126-
<MaybeDndProvider dndManager={dndManager}>
127-
{children}
128-
</MaybeDndProvider>
129-
</StylesProvider>
130-
</ThemeProvider>
131-
</LiveAnnouncer>
124+
<MaybeDndProvider dndManager={dndManager}>
125+
{children}
126+
</MaybeDndProvider>
127+
</StylesProvider>
128+
</ThemeProvider>
132129
</I18nextProvider>
133130
</FullScreenShim>
134131
);

src/components/SearchHit.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,20 @@ export class SearchHit extends Component {
5555
const {
5656
annotation, annotationLabel, announcer, canvasLabel, hit, index, t, total,
5757
} = this.props;
58-
if (!hit) return;
58+
if (!hit || !announcer) return;
5959
const truncatedHit = new TruncatedHit(hit, annotation);
6060

61-
announcer([
62-
t('pagination', { current: index + 1, total }),
63-
canvasLabel,
64-
annotationLabel,
65-
truncatedHit.before,
66-
truncatedHit.match,
67-
truncatedHit.after,
68-
].join(' '));
61+
announcer(
62+
[
63+
t('pagination', { current: index + 1, total }),
64+
canvasLabel,
65+
annotationLabel,
66+
truncatedHit.before,
67+
truncatedHit.match,
68+
truncatedHit.after,
69+
].join(' '),
70+
'polite',
71+
);
6972
}
7073

7174
/** */
@@ -157,7 +160,7 @@ SearchHit.propTypes = {
157160
}),
158161
annotationId: PropTypes.string,
159162
annotationLabel: PropTypes.string,
160-
announcer: PropTypes.func.isRequired,
163+
announcer: PropTypes.func,
161164
canvasLabel: PropTypes.string,
162165
classes: PropTypes.objectOf(PropTypes.string),
163166
companionWindowId: PropTypes.string,
@@ -186,6 +189,7 @@ SearchHit.defaultProps = {
186189
annotation: undefined,
187190
annotationId: undefined,
188191
annotationLabel: undefined,
192+
announcer: undefined,
189193
canvasLabel: undefined,
190194
classes: {},
191195
companionWindowId: undefined,

src/components/SearchResults.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Button from '@material-ui/core/Button';
44
import List from '@material-ui/core/List';
55
import Typography from '@material-ui/core/Typography';
66
import BackIcon from '@material-ui/icons/ArrowBackSharp';
7-
import { LiveMessenger } from 'react-aria-live';
7+
import { announce } from '@react-aria/live-announcer';
88
import SearchHit from '../containers/SearchHit';
99
import { ScrollTo } from './ScrollTo';
1010

@@ -32,7 +32,7 @@ export class SearchResults extends Component {
3232
* Return SearchHits for every hit in the response
3333
* Return SearchHits for every annotation in the response if there are no hits
3434
*/
35-
renderSearchHitsAndAnnotations(announcer) {
35+
renderSearchHitsAndAnnotations() {
3636
const {
3737
companionWindowId,
3838
containerRef,
@@ -47,7 +47,7 @@ export class SearchResults extends Component {
4747
if (searchHits.length === 0 && searchAnnotations.length > 0) {
4848
return searchAnnotations.map((anno, index) => (
4949
<SearchHit
50-
announcer={announcer}
50+
announcer={announce}
5151
annotationId={anno.id}
5252
companionWindowId={companionWindowId}
5353
containerRef={containerRef}
@@ -63,7 +63,7 @@ export class SearchResults extends Component {
6363

6464
return searchHits.map((hit, index) => (
6565
<SearchHit
66-
announcer={announcer}
66+
announcer={announce}
6767
containerRef={containerRef}
6868
companionWindowId={companionWindowId}
6969
key={hit.annotations[0]}
@@ -118,9 +118,7 @@ export class SearchResults extends Component {
118118
</Typography>
119119
)}
120120
<List disablePadding>
121-
<LiveMessenger>
122-
{({ announcePolite }) => this.renderSearchHitsAndAnnotations(announcePolite) }
123-
</LiveMessenger>
121+
{ this.renderSearchHitsAndAnnotations() }
124122
</List>
125123
{ nextSearch && (
126124
<Button

0 commit comments

Comments
 (0)