Skip to content
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
13 changes: 8 additions & 5 deletions packages/base/src/SearchBar/SearchBar-android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,16 @@ export class SearchBarAndroid extends Component<
hasFocus: false,
isEmpty: value ? value === '' : true,
};
this.keyboardListener = Keyboard.addListener(
'keyboardDidHide',
this._keyboardDidHide
);
if (this.props.onKeyboardHide) {
this.keyboardListener = Keyboard.addListener(
'keyboardDidHide',
this._keyboardDidHide
);
}
}
_keyboardDidHide = () => {
this.cancel();
this.blur();
this.props.onKeyboardHide?.();
};

componentWillUnmount() {
Expand Down
8 changes: 6 additions & 2 deletions packages/base/src/SearchBar/__tests__/SearchBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ describe('SearchBar wrapper component', () => {
Keyboard.addListener = originalAddListener;
});
it('should subscribe to KeyboardDidClose event', () => {
renderWithWrapper(<SearchBar platform="android" />);
renderWithWrapper(
<SearchBar platform="android" onKeyboardHide={() => {}} />
);
expect(Keyboard.addListener).toHaveBeenCalled();
});

it('should call listener.remove on unmount', () => {
const component = renderWithWrapper(<SearchBar platform="android" />);
const component = renderWithWrapper(
<SearchBar platform="android" onKeyboardHide={() => {}} />
);
component.unmount();
expect(mockListener.remove).toHaveBeenCalled();
});
Expand Down
8 changes: 6 additions & 2 deletions packages/base/src/SearchBar/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ export type SearchBarAndroidProps = SearchBarBaseProps & {
platform?: 'android';
cancelIcon?: IconNode;
/**
* @type Callback Function on cancel icon press
* Callback Function on cancel icon press
*/
onCancel?: () => any;
/**
* Callback Function on keyboard hides
*/
onKeyboardHide?: () => any;
};

export type SearchBarIosProps = SearchBarBaseProps & {
Expand All @@ -38,7 +42,7 @@ export type SearchBarIosProps = SearchBarBaseProps & {
searchIcon?: IconNode;
clearIcon?: IconNode;
/**
* @type Callback Function on cancel icon press
* Callback Function on cancel icon press
*/
onCancel?: () => any;
};
Expand Down
41 changes: 21 additions & 20 deletions website/docs/components/SearchBar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,27 @@ Includes all [Input](input#props) props.

<div class='table-responsive'>

| Name | Type | Default | Description |
| ------------------------- | ------------------------------- | --------- | -------------------------- |
| `cancelButtonProps` | Text Style | | |
| `cancelButtonTitle` | string | | |
| `cancelIcon` | IconNode | | |
| `clearIcon` | IconNode | | Clear Icon |
| `containerStyle` | View Style | | Style for container |
| `inputContainerStyle` | View Style | | Style for input container |
| `inputStyle` | Text Style | | Input Style |
| `leftIconContainerStyle` | View Style | | Left Icon Container Style |
| `lightTheme` | boolean | | |
| `loadingProps` | ActivityIndicatorProps | | ActivityIndicatorProps |
| `onCancel` | `(() => any)` \| `(() => any)` | | |
| `onClear` | Function | | |
| `platform` | `default` \| `android` \| `ios` | `default` | |
| `rightIconContainerStyle` | View Style | | Right Icon Container Style |
| `round` | boolean | | |
| `searchIcon` | IconNode | | Icon for search |
| `showCancel` | boolean | | Show cancel |
| `showLoading` | boolean | | Show loading |
| Name | Type | Default | Description |
| ------------------------- | ------------------------------- | --------- | -------------------------------------- |
| `cancelButtonProps` | Text Style | | |
| `cancelButtonTitle` | string | | |
| `cancelIcon` | IconNode | | |
| `clearIcon` | IconNode | | Clear Icon |
| `containerStyle` | View Style | | Style for container |
| `inputContainerStyle` | View Style | | Style for input container |
| `inputStyle` | Text Style | | Input Style |
| `leftIconContainerStyle` | View Style | | Left Icon Container Style |
| `lightTheme` | boolean | | |
| `loadingProps` | ActivityIndicatorProps | | ActivityIndicatorProps |
| `onCancel` | `(() => any)` \| `(() => any)` | | Callback Function on cancel icon press |
| `onClear` | Function | | |
| `onKeyboardHide` | Function | | Callback Function on keyboard hides |
| `platform` | `default` \| `android` \| `ios` | `default` | |
| `rightIconContainerStyle` | View Style | | Right Icon Container Style |
| `round` | boolean | | |
| `searchIcon` | IconNode | | Icon for search |
| `showCancel` | boolean | | Show cancel |
| `showLoading` | boolean | | Show loading |

</div>

Expand Down