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

[Filters] Add onQueryFocused callback #1948

Merged
merged 1 commit into from
Aug 12, 2019
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
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
- Exported `AppliedFilterInterface` and `FilterInterface` from `Filters` ([#1924](https://github.com/Shopify/polaris-react/pull/1924))
- Improved color contrast of links inside `Banner` ([#1651](https://github.com/Shopify/polaris-react/pull/1651))
- Add underline to Links and Plain button on hover, so it doesn't rely on color alone for accessibility ([#1885](https://github.com/Shopify/polaris-react/pull/1885))
- Add `onQueryFocus` callback prop to the `Filters` component ([#1948](https://github.com/Shopify/polaris-react/pull/1948))

### Bug fixes

Expand Down
4 changes: 4 additions & 0 deletions src/components/Filters/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export interface Props {
onClearAll(): void;
/** Callback when the query field is blurred */
onQueryBlur?(): void;
/** Callback when the query field is focused */
onQueryFocus?(): void;
/** The content to display inline with the controls */
children?: React.ReactNode;
}
Expand Down Expand Up @@ -133,6 +135,7 @@ class Filters extends React.Component<ComposedProps, State> {
queryValue,
onQueryBlur,
onQueryChange,
onQueryFocus,
focused,
onClearAll,
appliedFilters,
Expand Down Expand Up @@ -236,6 +239,7 @@ class Filters extends React.Component<ComposedProps, State> {
}
onChange={onQueryChange}
onBlur={onQueryBlur}
onFocus={onQueryFocus}
value={queryValue}
focused={focused}
label={
Expand Down
13 changes: 12 additions & 1 deletion src/components/Filters/tests/Filters.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import {ReactWrapper} from 'enzyme';
import {matchMedia} from '@shopify/jest-dom-mocks';
import {Button, Popover, Sheet, Tag} from 'components';
import {Button, Popover, Sheet, Tag, TextField} from 'components';

import {
mountWithAppProvider,
Expand Down Expand Up @@ -50,6 +50,17 @@ describe('<Filters />', () => {
matchMedia.restore();
});

it('calls the onQueryFocus callback when the query field is focused', () => {
const onQueryFocus = jest.fn();
const filters = mountWithAppProvider(
<Filters {...mockProps} onQueryFocus={onQueryFocus} />,
);

trigger(filters.find(TextField), 'onFocus');

expect(onQueryFocus).toHaveBeenCalledTimes(1);
});

describe('toggleFilters()', () => {
it('opens the sheet on toggle button click', () => {
const resourceFilters = mountWithAppProvider(<Filters {...mockProps} />);
Expand Down