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
2 changes: 2 additions & 0 deletions src/components/EmojiPicker/EmojiPickerMenu/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji, ref}: EmojiPickerMenuPro
setSearchText(text);
filterEmojis(text);
}}
value={searchText}
shouldHideClearButton={false}
submitBehavior={filteredEmojis.length > 0 ? 'blurAndSubmit' : 'submit'}
sentryLabel={CONST.SENTRY_LABEL.EMOJI_PICKER.SEARCH_INPUT}
/>
Expand Down
3 changes: 2 additions & 1 deletion src/components/EmojiPicker/EmojiPickerMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji, ref}: EmojiPickerMenuPro
setSearchText(text);
filterEmojis(text);
}}
defaultValue=""
value={searchText}
shouldHideClearButton={false}
ref={searchInputRef}
autoFocus={shouldFocusInputOnScreenFocus}
onFocus={() => {
Expand Down
1 change: 1 addition & 0 deletions src/components/SelectionList/components/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function TextInput({
onSubmitEditing={onSubmit}
submitBehavior={dataLength ? 'blurAndSubmit' : 'submit'}
isLoading={isLoading}
shouldHideClearButton={false}
testID="selection-list-text-input"
errorText={errorText}
autoCorrect={!disableAutoCorrect}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ function AddAgentRuleSuggestionsTab({onSelectSuggestion}: AddAgentRuleSuggestion
accessibilityLabel={translate('workspace.rules.agentRules.findSuggestion')}
value={searchValue}
onChangeText={setSearchValue}
shouldHideClearButton={false}
autoGrowHeight={false}
role={CONST.ROLE.SEARCHBOX}
/>
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/BaseSelectionListTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,38 @@ describe('BaseSelectionList', () => {
expect(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}70`)).toBeSelected();
});

it('should show a clear button once the search field has text and clear the search when it is pressed', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Givne when then

function SearchableListWrapper() {
const [searchText, setSearchText] = useState('');

const filteredItems = searchText ? mockItems.filter((item) => item.text.toLowerCase().includes(searchText.toLowerCase())) : mockItems;

return (
<SelectionListRenderer
data={filteredItems}
searchText={searchText}
setSearchText={setSearchText}
canSelectMultiple={false}
/>
);
}

render(<SearchableListWrapper />);

// The clear button is only rendered once the field has text
expect(screen.queryByLabelText('common.clear')).toBeFalsy();

fireEvent.changeText(screen.getByTestId('selection-list-text-input'), 'Item 0');

expect(screen.queryByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}1`)).toBeFalsy();

fireEvent.press(screen.getByLabelText('common.clear'));

expect(screen.getByTestId('selection-list-text-input')).toHaveProp('value', '');
expect(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}1`)).toBeTruthy();
expect(screen.queryByLabelText('common.clear')).toBeFalsy();
});

it('should render the selection-list testID', () => {
render(
<SelectionListRenderer
Expand Down
Loading