A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
ciphermask/ui/components/component-library/text-field-search
George Marshall 6907c4a565
Adding `TextFieldSearch` component (#16296)
2 years ago
..
README.mdx Adding `TextFieldSearch` component (#16296) 2 years ago
index.js Adding `TextFieldSearch` component (#16296) 2 years ago
text-field-search.js Adding `TextFieldSearch` component (#16296) 2 years ago
text-field-search.scss Adding `TextFieldSearch` component (#16296) 2 years ago
text-field-search.stories.js Adding `TextFieldSearch` component (#16296) 2 years ago
text-field-search.test.js Adding `TextFieldSearch` component (#16296) 2 years ago

README.mdx

import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';

import { TextFieldSearch } from './text-field-search';

# TextFieldSearch

The `TextFieldSearch` allows users to enter text to search. It wraps the `TextField` component that adds a search icon to the left of the input.

<Canvas>
<Story id="ui-components-component-library-text-field-search-text-field-search-stories-js--default-story" />
</Canvas>

## Props

The `TextFieldSearch` accepts all props below as well as all [Box](/docs/ui-components-ui-box-box-stories-js--default-story#props), [TextField](/docs/ui-components-component-library-text-field-text-field-stories-js--default-story#props) component props

<ArgsTable of={TextFieldSearch} />

### Show Clear Button

Use the `showClearButton` prop to display a clear button when `TextFieldSearch` has a value. Use the `clearButtonOnClick` prop to pass an `onClick` event handler to clear the value of the input.

Defaults to `true`

The clear button uses [ButtonIcon](/docs/ui-components-component-library-button-icon-button-icon-stories-js--default-story) and accepts all props from that component.

**NOTE: The `showClearButton` only works with a controlled input.**

<Canvas>
<Story id="ui-components-component-library-text-field-search-text-field-search-stories-js--show-clear-button" />
</Canvas>

```jsx
import { TextFieldSearch } from '../../ui/component-library/text-field';

const [value, setValue] = useState('show clear');

const handleOnChange = (e) => {
setValue(e.target.value);
};

const handleOnClear = () => {
setValue('');
};

<TextFieldSearch
placeholder="Enter text to show clear"
value={value}
onChange={handleOnChange}
clearButtonOnClick={handleOnClear}
/>;
```

### Clear Button Props

Use the `clearButtonProps` to access other props of the clear button.

<Canvas>
<Story id="ui-components-component-library-text-field-search-text-field-search-stories-js--clear-button-props" />
</Canvas>

```jsx
import React, { useState } from 'react';
import {
SIZES,
COLORS,
BORDER_RADIUS,
} from '../../../helpers/constants/design-system';

import { TextFieldSearch } from '../../ui/component-library/text-field';

const [value, setValue] = useState('show clear');

const handleOnChange = (e) => {
setValue(e.target.value);
};

const handleOnClear = () => {
setValue('');
};

<TextFieldSearch
value={value}
onChange={handleOnChange}
clearButtonOnClick={handleOnClear}
clearButtonProps={{
backgroundColor: COLORS.BACKGROUND_ALTERNATIVE,
borderRadius: BORDER_RADIUS.XS,
'data-testid': 'clear-button',
}}
/>;
```