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

SearchBox: role=search is removed, but can be optionally defined via role prop. #15450

Merged
merged 7 commits into from
Oct 10, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "minor",
"comment": "SearchBox: role=search on root div is now opt in; if you want it, you must provide it as a role prop.",
"packageName": "office-ui-fabric-react",
"email": "[email protected]",
"dependentChangeType": "patch",
"date": "2020-10-09T18:54:58.004Z"
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class SearchBoxBase extends React.Component<ISearchBoxProps, ISearchBoxSt
clearButtonProps,
disableAnimation,
iconProps,
role,
dzearing marked this conversation as resolved.
Show resolved Hide resolved
id = this._fallbackId,
} = this.props;
const { value, hasFocus } = this.state;
Expand All @@ -97,10 +98,11 @@ export class SearchBoxBase extends React.Component<ISearchBoxProps, ISearchBoxSt
'onFocus',
'onBlur',
'value',
'role',
]);

return (
<div role="search" ref={this._rootElement} className={classNames.root} onFocusCapture={this._onFocusCapture}>
<div role={role} ref={this._rootElement} className={classNames.root} onFocusCapture={this._onFocusCapture}>
<div className={classNames.iconContainer} onClick={this._onClickFocus} aria-hidden={true}>
<Icon iconName="Search" {...iconProps} className={classNames.icon} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import { SearchBox } from './SearchBox';
import { KeyCodes } from '../../Utilities';
import { ISearchBoxProps } from './SearchBox.types';
import { ISearchBoxState, SearchBoxBase } from './SearchBox.base';
import { resetIds } from '@uifabric/utilities';

describe('SearchBox', () => {
let component: renderer.ReactTestRenderer | undefined;
let wrapper: ReactWrapper<ISearchBoxProps, ISearchBoxState, SearchBoxBase> | undefined;

beforeEach(() => {
resetIds();
});

afterEach(() => {
if (component) {
component.unmount();
Expand All @@ -27,6 +32,12 @@ describe('SearchBox', () => {
expect(tree).toMatchSnapshot();
});

it('renders SearchBox role on the container div', () => {
wrapper = mount(<SearchBox role="search" />);

expect(wrapper.getDOMNode().getAttribute('role')).toEqual('search');
});

it('can execute an onClick on clear button', () => {
let clickExecuted = false;
wrapper = mount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ exports[`SearchBox renders SearchBox correctly 1`] = `
color: #005a9e;
}
onFocusCapture={[Function]}
role="search"
>
<div
aria-hidden={true}
Expand Down Expand Up @@ -178,7 +177,6 @@ exports[`SearchBox renders SearchBox without animation correctly 1`] = `
color: #005a9e;
}
onFocusCapture={[Function]}
role="search"
>
<div
aria-hidden={true}
Expand Down Expand Up @@ -257,7 +255,7 @@ exports[`SearchBox renders SearchBox without animation correctly 1`] = `
&::-ms-clear {
display: none;
}
id="SearchBox5"
id="SearchBox0"
onBlur={[Function]}
onChange={[Function]}
onInput={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Array [
color: #005a9e;
}
onFocusCapture={[Function]}
role="search"
>
<div
aria-hidden={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ exports[`Component Examples renders SearchBox.CustomIcon.Example.tsx correctly 1
color: #005a9e;
}
onFocusCapture={[Function]}
role="search"
>
<div
aria-hidden={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ exports[`Component Examples renders SearchBox.Disabled.Example.tsx correctly 1`]
color: #005a9e;
}
onFocusCapture={[Function]}
role="search"
>
<div
aria-hidden={true}
Expand Down Expand Up @@ -208,7 +207,6 @@ exports[`Component Examples renders SearchBox.Disabled.Example.tsx correctly 1`]
color: #005a9e;
}
onFocusCapture={[Function]}
role="search"
>
<div
aria-hidden={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ exports[`Component Examples renders SearchBox.FullSize.Example.tsx correctly 1`]
color: #005a9e;
}
onFocusCapture={[Function]}
role="search"
>
<div
aria-hidden={true}
Expand Down Expand Up @@ -197,7 +196,6 @@ exports[`Component Examples renders SearchBox.FullSize.Example.tsx correctly 1`]
color: #005a9e;
}
onFocusCapture={[Function]}
role="search"
>
<div
aria-hidden={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ exports[`Component Examples renders SearchBox.Small.Example.tsx correctly 1`] =
color: #005a9e;
}
onFocusCapture={[Function]}
role="search"
>
<div
aria-hidden={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ exports[`Component Examples renders SearchBox.Underlined.Example.tsx correctly 1
color: #005a9e;
}
onFocusCapture={[Function]}
role="search"
>
<div
aria-hidden={true}
Expand Down
1 change: 1 addition & 0 deletions packages/react-next/etc/react-next.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2413,6 +2413,7 @@ export interface ISearchBoxProps extends React.InputHTMLAttributes<HTMLInputElem
onEscape?: (ev?: any) => void;
onSearch?: (newValue: any) => void;
placeholder?: string;
role?: string;
styles?: IStyleFunctionOrObject<ISearchBoxStyleProps, ISearchBoxStyles>;
theme?: ITheme;
underlined?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ export interface ISearchBoxProps
*/
underlined?: boolean;

/**
* The role assigned to the root DIV element of the SearchBox, useful for defining a landmark role, such as "search".
*/
role?: string;
dzearing marked this conversation as resolved.
Show resolved Hide resolved

/**
* Theme (provided through customization).
*/
Expand Down