Skip to content

Commit

Permalink
SearchBox: Making role on root div opt in (microsoft#15621)
Browse files Browse the repository at this point in the history
<!--
!!!!!!! IMPORTANT !!!!!!!

Due to work we're currently doing to prepare master branch for our version 8 beta release,
please hold-off submitting the PR until around October 12 if it's not urgent.
If it is urgent, please submit the PR targeting the 7.0 branch.

This change does not apply to react-northstar contributors.

See microsoft#15222 for more details. Sorry for the inconvenience and short notice.
-->

#### Pull request checklist

- [ ] Addresses an existing issue: Fixes #0000
- [x] Include a change request file using `$ yarn change`

#### Description of changes

_Cherry-pick of microsoft#15450._

_Original PR description:_

## Before:

This JSX:
```
<SearchBox />
```
Renders this HTML: 
```jsx
<div role="search">
  <input ... />
</div>
```

## After:

This JSX:
```
<SearchBox />
<SearchBox role="search" />
```
Renders this HTML: 
```jsx
<div>
  <input ... />
</div>

<div role="search">
  <input ... />
</div>
```
  • Loading branch information
khmakoto committed Oct 20, 2020
1 parent 820f5a3 commit b14a4ed
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "patch",
"comment": "SearchBox: Making role on root div opt in.",
"packageName": "@fluentui/react-internal",
"email": "humbertomakotomorimoto@gmail.com",
"dependentChangeType": "patch",
"date": "2020-10-20T20:28:47.909Z"
}
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-internal/etc/react-internal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4461,6 +4461,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 @@ -57,6 +57,7 @@ export const SearchBoxBase: React.FunctionComponent<ISearchBoxProps> = React.for
onEscape,
onSearch,
iconProps,
role,
} = props;

const classNames = getClassNames(styles!, {
Expand All @@ -75,6 +76,7 @@ export const SearchBoxBase: React.FunctionComponent<ISearchBoxProps> = React.for
'onFocus',
'onBlur',
'value',
'role',
]);

const onClear = React.useCallback(
Expand Down Expand Up @@ -155,7 +157,7 @@ export const SearchBoxBase: React.FunctionComponent<ISearchBoxProps> = React.for
useComponentRef(props.componentRef, inputElementRef, hasFocus);

return (
<div role="search" ref={mergedRootRef} className={classNames.root} onFocusCapture={onFocusCapture}>
<div role={role} ref={mergedRootRef} className={classNames.root} onFocusCapture={onFocusCapture}>
<div className={classNames.iconContainer} onClick={onClickFocus} aria-hidden>
<Icon iconName="Search" {...iconProps} className={classNames.icon} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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 @@ -104,6 +104,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;

/**
* Theme (provided through customization).
*/
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

0 comments on commit b14a4ed

Please sign in to comment.