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: Making role on root div opt in #15621

Merged
merged 2 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all 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": "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