Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(search): switch search role from datatable to search, add labeledby #5330

Merged
merged 8 commits into from
Feb 14, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ const TableToolbarSearch = ({
return (
<div
tabIndex={expandedState ? '-1' : tabIndex}
role="search"
ref={searchRef}
onClick={event => onClick(event)}
onFocus={event => handleExpand(event, true)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2245,7 +2245,6 @@ exports[`DataTable should render 1`] = `
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
role="search"
tabIndex="0"
>
<Search
Expand All @@ -2261,7 +2260,9 @@ exports[`DataTable should render 1`] = `
value=""
>
<div
aria-labelledby="custom-id-search"
className="bx--search bx--search--sm"
role="search"
>
<ForwardRef(Search16)
className="bx--search-magnifier"
Expand Down Expand Up @@ -2298,6 +2299,7 @@ exports[`DataTable should render 1`] = `
<label
className="bx--label"
htmlFor="custom-id"
id="custom-id-search"
>
Filter table
</label>
Expand Down Expand Up @@ -3242,7 +3244,6 @@ exports[`DataTable sticky header should render 1`] = `
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
role="search"
tabIndex="0"
>
<Search
Expand All @@ -3258,7 +3259,9 @@ exports[`DataTable sticky header should render 1`] = `
value=""
>
<div
aria-labelledby="custom-id-search"
className="bx--search bx--search--sm"
role="search"
>
<ForwardRef(Search16)
className="bx--search-magnifier"
Expand Down Expand Up @@ -3295,6 +3298,7 @@ exports[`DataTable sticky header should render 1`] = `
<label
className="bx--label"
htmlFor="custom-id"
id="custom-id-search"
>
Filter table
</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ exports[`DataTable.TableToolbarSearch should render 1`] = `
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
role="search"
tabIndex="0"
>
<Search
Expand All @@ -31,7 +30,9 @@ exports[`DataTable.TableToolbarSearch should render 1`] = `
value=""
>
<div
aria-labelledby="custom-id-search"
className="bx--search bx--search--sm custom-class"
role="search"
>
<ForwardRef(Search16)
className="bx--search-magnifier"
Expand Down Expand Up @@ -68,6 +69,7 @@ exports[`DataTable.TableToolbarSearch should render 1`] = `
<label
className="bx--label"
htmlFor="custom-id"
id="custom-id-search"
>
Filter table
</label>
Expand Down
6 changes: 4 additions & 2 deletions packages/react/src/components/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ export default class Search extends Component {

const CloseIconX = size === 'xl' ? Close20 : Close16;

const searchId = `${id}-search`;

return (
<div className={searchClasses}>
<div role="search" aria-labelledby={searchId} className={searchClasses}>
<Search16 className={`${prefix}--search-magnifier`} />
<label htmlFor={id} className={`${prefix}--label`}>
<label id={searchId} htmlFor={id} className={`${prefix}--label`}>
{labelText}
</label>
<input
Expand Down