Skip to content

Commit bd8e1e6

Browse files
authored
fix(content-picker): add accessible names to Footer (#3177)
* chore: add accessible names to Footer * fix(content-picker): tooltip bug fix * fix(content-picker): add test * fix(content-picker): update test
1 parent fead6e4 commit bd8e1e6

2 files changed

Lines changed: 67 additions & 51 deletions

File tree

‎src/elements/content-picker/Footer.js‎

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*/
66

77
import React from 'react';
8+
import { injectIntl, FormattedMessage } from 'react-intl';
89
import type { Node } from 'react';
9-
import { FormattedMessage } from 'react-intl';
10+
1011
import type { Collection, BoxItem } from '../../common/types/core';
1112
import Button from '../../components/button';
1213
import ButtonGroup from '../../components/button-group';
@@ -24,6 +25,7 @@ type Props = {
2425
chooseButtonLabel?: string,
2526
currentCollection: Collection,
2627
hasHitSelectionLimit: boolean,
28+
intl: any,
2729
isSingleSelect: boolean,
2830
onCancel: Function,
2931
onChoose: Function,
@@ -45,6 +47,7 @@ const Footer = ({
4547
selectedItems,
4648
onSelectedClick,
4749
hasHitSelectionLimit,
50+
intl,
4851
isSingleSelect,
4952
onCancel,
5053
onChoose,
@@ -53,55 +56,61 @@ const Footer = ({
5356
children,
5457
renderCustomActionButtons,
5558
showSelectedButton,
56-
}: Props) => (
57-
<footer className="bcp-footer">
58-
<div className="bcp-footer-left">
59-
{showSelectedButton && !isSingleSelect && (
60-
<Button className="bcp-selected" onClick={onSelectedClick} type="button">
61-
<FormattedMessage
62-
className="bcp-selected-count"
63-
{...messages.selected}
64-
values={{ count: selectedCount }}
65-
/>
66-
{hasHitSelectionLimit && (
67-
<span className="bcp-selected-max">
68-
(<FormattedMessage {...messages.max} />)
69-
</span>
70-
)}
71-
</Button>
72-
)}
73-
</div>
74-
<div className="bcp-footer-right">
75-
{children}
59+
}: Props) => {
60+
const cancelMessage = intl.formatMessage(messages.cancel);
61+
const chooseMessage = intl.formatMessage(messages.choose);
62+
return (
63+
<footer className="bcp-footer">
64+
<div className="bcp-footer-left">
65+
{showSelectedButton && !isSingleSelect && (
66+
<Button className="bcp-selected" onClick={onSelectedClick} type="button">
67+
<FormattedMessage
68+
className="bcp-selected-count"
69+
{...messages.selected}
70+
values={{ count: selectedCount }}
71+
/>
72+
{hasHitSelectionLimit && (
73+
<span className="bcp-selected-max">
74+
(<FormattedMessage {...messages.max} />)
75+
</span>
76+
)}
77+
</Button>
78+
)}
79+
</div>
80+
<div className="bcp-footer-right">
81+
{children}
7682

77-
{renderCustomActionButtons ? (
78-
renderCustomActionButtons({
79-
currentFolderId: currentCollection.id,
80-
currentFolderName: currentCollection.name,
81-
onCancel,
82-
onChoose,
83-
selectedCount,
84-
selectedItems,
85-
})
86-
) : (
87-
<ButtonGroup className="bcp-footer-actions">
88-
<Tooltip text={cancelButtonLabel || <FormattedMessage {...messages.cancel} />}>
89-
<Button onClick={onCancel} type="button">
90-
<IconClose height={16} width={16} />
91-
</Button>
92-
</Tooltip>
93-
<Tooltip
94-
isDisabled={!selectedCount}
95-
text={chooseButtonLabel || <FormattedMessage {...messages.choose} />}
96-
>
97-
<PrimaryButton isDisabled={!selectedCount} onClick={onChoose} type="button">
98-
<IconCheck color="#fff" height={16} width={16} />
99-
</PrimaryButton>
100-
</Tooltip>
101-
</ButtonGroup>
102-
)}
103-
</div>
104-
</footer>
105-
);
83+
{renderCustomActionButtons ? (
84+
renderCustomActionButtons({
85+
currentFolderId: currentCollection.id,
86+
currentFolderName: currentCollection.name,
87+
onCancel,
88+
onChoose,
89+
selectedCount,
90+
selectedItems,
91+
})
92+
) : (
93+
<ButtonGroup className="bcp-footer-actions">
94+
<Tooltip text={cancelButtonLabel || cancelMessage}>
95+
<Button aria-label={cancelMessage} onClick={onCancel} type="button">
96+
<IconClose height={16} width={16} />
97+
</Button>
98+
</Tooltip>
99+
<Tooltip isDisabled={!selectedCount} text={chooseButtonLabel || chooseMessage}>
100+
<PrimaryButton
101+
aria-label={chooseMessage}
102+
isDisabled={!selectedCount}
103+
onClick={onChoose}
104+
type="button"
105+
>
106+
<IconCheck color="#fff" height={16} width={16} />
107+
</PrimaryButton>
108+
</Tooltip>
109+
</ButtonGroup>
110+
)}
111+
</div>
112+
</footer>
113+
);
114+
};
106115

107-
export default Footer;
116+
export default injectIntl(Footer);

‎src/elements/content-picker/__tests__/Footer.test.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ describe('elements/content-picker/Footer', () => {
2525
expect(wrapper.find('.footer-child').length).toBe(1);
2626
});
2727

28+
test('should render Footer buttons with aria-label', () => {
29+
const buttons = getWrapper().find('Button');
30+
31+
expect(buttons.at(0).prop('aria-label')).toBe('Cancel');
32+
expect(buttons.at(1).prop('aria-label')).toBe('Choose');
33+
});
34+
2835
test('should render Footer with custom action button', () => {
2936
const renderCustomActionButtons = jest.fn();
3037

0 commit comments

Comments
 (0)