Skip to content
This repository was archived by the owner on Oct 19, 2021. It is now read-only.

Commit e75f985

Browse files
authored
fix(search): add button to clear icon for a11y (#864)
1 parent 2c2409c commit e75f985

File tree

4 files changed

+62
-55
lines changed

4 files changed

+62
-55
lines changed

src/components/DataTable/__tests__/__snapshots__/DataTable-test.js.snap

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -937,35 +937,37 @@ exports[`DataTable should render 1`] = `
937937
placeholder="Search"
938938
type="text"
939939
/>
940-
<Icon
940+
<button
941941
className="bx--search-close bx--search-close--hidden"
942-
description="close"
943-
fillRule="evenodd"
944-
name="close--glyph"
945942
onClick={[Function]}
946-
role="img"
943+
type="button"
947944
>
948-
<svg
949-
alt="close"
950-
aria-label="close"
951-
className="bx--search-close bx--search-close--hidden"
945+
<Icon
946+
description="close"
952947
fillRule="evenodd"
953-
height="16"
954948
name="close--glyph"
955-
onClick={[Function]}
956949
role="img"
957-
viewBox="0 0 16 16"
958-
width="16"
959950
>
960-
<title>
961-
close
962-
</title>
963-
<path
964-
d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm3.5 10.1l-1.4 1.4L8 9.4l-2.1 2.1-1.4-1.4L6.6 8 4.5 5.9l1.4-1.4L8 6.6l2.1-2.1 1.4 1.4L9.4 8l2.1 2.1z"
965-
key="key0"
966-
/>
967-
</svg>
968-
</Icon>
951+
<svg
952+
alt="close"
953+
aria-label="close"
954+
fillRule="evenodd"
955+
height="16"
956+
name="close--glyph"
957+
role="img"
958+
viewBox="0 0 16 16"
959+
width="16"
960+
>
961+
<title>
962+
close
963+
</title>
964+
<path
965+
d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm3.5 10.1l-1.4 1.4L8 9.4l-2.1 2.1-1.4-1.4L6.6 8 4.5 5.9l1.4-1.4L8 6.6l2.1-2.1 1.4 1.4L9.4 8l2.1 2.1z"
966+
key="key0"
967+
/>
968+
</svg>
969+
</Icon>
970+
</button>
969971
</div>
970972
</Search>
971973
</div>

src/components/DataTable/__tests__/__snapshots__/TableToolbarSearch-test.js.snap

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,35 +66,37 @@ exports[`DataTable.TableToolbarSearch should render 1`] = `
6666
placeholder="Search"
6767
type="text"
6868
/>
69-
<Icon
69+
<button
7070
className="bx--search-close bx--search-close--hidden"
71-
description="close"
72-
fillRule="evenodd"
73-
name="close--glyph"
7471
onClick={[Function]}
75-
role="img"
72+
type="button"
7673
>
77-
<svg
78-
alt="close"
79-
aria-label="close"
80-
className="bx--search-close bx--search-close--hidden"
74+
<Icon
75+
description="close"
8176
fillRule="evenodd"
82-
height="16"
8377
name="close--glyph"
84-
onClick={[Function]}
8578
role="img"
86-
viewBox="0 0 16 16"
87-
width="16"
8879
>
89-
<title>
90-
close
91-
</title>
92-
<path
93-
d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm3.5 10.1l-1.4 1.4L8 9.4l-2.1 2.1-1.4-1.4L6.6 8 4.5 5.9l1.4-1.4L8 6.6l2.1-2.1 1.4 1.4L9.4 8l2.1 2.1z"
94-
key="key0"
95-
/>
96-
</svg>
97-
</Icon>
80+
<svg
81+
alt="close"
82+
aria-label="close"
83+
fillRule="evenodd"
84+
height="16"
85+
name="close--glyph"
86+
role="img"
87+
viewBox="0 0 16 16"
88+
width="16"
89+
>
90+
<title>
91+
close
92+
</title>
93+
<path
94+
d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm3.5 10.1l-1.4 1.4L8 9.4l-2.1 2.1-1.4-1.4L6.6 8 4.5 5.9l1.4-1.4L8 6.6l2.1-2.1 1.4 1.4L9.4 8l2.1 2.1z"
95+
key="key0"
96+
/>
97+
</svg>
98+
</Icon>
99+
</button>
98100
</div>
99101
</Search>
100102
</div>

src/components/Search/Search-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ describe('Search', () => {
7575
describe('Large Search', () => {
7676
describe('buttons', () => {
7777
const btns = wrapper.find('button');
78-
const sortBtn = btns.first();
78+
const sortBtn = btns.last();
7979

80-
it('should be two buttons', () => {
81-
expect(btns.length).toBe(2);
80+
it('should be three buttons', () => {
81+
expect(btns.length).toBe(3);
8282
});
8383

8484
it('should have type="button"', () => {
@@ -145,9 +145,9 @@ describe('Search', () => {
145145
expect(smallContainer.hasClass('bx--search--sm')).toEqual(true);
146146
});
147147

148-
it('should not have buttons', () => {
148+
it('should only have 1 button (clear)', () => {
149149
const btn = small.find('button');
150-
expect(btn.length).toEqual(0);
150+
expect(btn.length).toEqual(1);
151151
});
152152

153153
it('renders one Icon', () => {
@@ -198,13 +198,13 @@ describe('Search', () => {
198198
});
199199

200200
it('should toggle layout to "grid" when clicked', () => {
201-
const button = wrapper.find('button').at(1);
201+
const button = wrapper.find('button').at(2);
202202
button.simulate('click');
203203
const icon = wrapper.find(Icon).at(3);
204204
expect(icon.props().name).toEqual('grid');
205205
});
206206
it('should toggle layout to "list" when clicked and currently set to "grid"', () => {
207-
const button = wrapper.find('button').at(1);
207+
const button = wrapper.find('button').at(2);
208208
wrapper.setState({
209209
format: 'grid',
210210
});

src/components/Search/Search.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default class Search extends Component {
1616
id: PropTypes.string,
1717
searchButtonLabelText: PropTypes.string,
1818
layoutButtonLabelText: PropTypes.string,
19+
closeButtonLabelText: PropTypes.string,
1920
};
2021

2122
static defaultProps = {
@@ -66,6 +67,7 @@ export default class Search extends Component {
6667
labelText,
6768
searchButtonLabelText,
6869
layoutButtonLabelText,
70+
closeButtonLabelText,
6971
small,
7072
children,
7173
...other
@@ -108,12 +110,13 @@ export default class Search extends Component {
108110
this.input = input;
109111
}}
110112
/>
111-
<Icon
112-
name="close--glyph"
113-
description="close"
113+
<button
114114
className={clearClasses}
115115
onClick={this.clearInput}
116-
/>
116+
type="button"
117+
aria-label={closeButtonLabelText}>
118+
<Icon name="close--glyph" description="close" />
119+
</button>
117120
{children}
118121
{renderButtons && (
119122
<SearchFilterButton labelText={searchButtonLabelText} />

0 commit comments

Comments
 (0)