Skip to content

Commit

Permalink
feat(TextField): add onClear (#3593)
Browse files Browse the repository at this point in the history
  • Loading branch information
gizeasy authored Apr 3, 2024
1 parent e3ac3aa commit 986cdac
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const TextFieldRender = <TYPE extends string>(
onKeyPressCapture,
onKeyUp,
onKeyUpCapture,

onClear,
...otherProps
} = usePropsHandler(COMPONENT_NAME, props, textFieldRef);

Expand Down Expand Up @@ -364,7 +364,7 @@ export const TextFieldRender = <TYPE extends string>(
type="button"
disabled={disabled}
tabIndex={-1}
onClick={handleClear}
onClick={onClear || handleClear}
className={cnTextField('ClearButton')}
>
<IconClear
Expand Down
35 changes: 18 additions & 17 deletions src/components/TextField/__stand__/TextField.dev.stand.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -489,23 +489,23 @@ export const TextFieldExampleMaskSetValue = () => {
});

return (
<Example>
<>
<FieldLabel className={cnMixSpace({ mB: 'xs' })}>Телефон</FieldLabel>
<FieldGroup>
<TextFieldMemo
placeholder="+7(999)999-99-99"
inputRef={ref}
defaultValue={defaultValue}
/>
<Button
iconLeft={IconRevert}
onClick={() => setValue(defaultValue)}
title="Сбросить"
/>
</FieldGroup>
</>
</Example>
<>
<FieldLabel className={cnMixSpace({ mB: 'xs' })}>Телефон</FieldLabel>
<FieldGroup>
<TextFieldMemo
placeholder="+7(999)999-99-99"
inputRef={ref}
defaultValue={defaultValue}
withClearButton
onClear={() => setValue('')}
/>
<Button
iconLeft={IconRevert}
onClick={() => setValue(defaultValue)}
title="Сбросить"
/>
</FieldGroup>
</>
);
};
```
Expand Down Expand Up @@ -742,6 +742,7 @@ import { TextField, useIMask } from '@consta/uikit/TextField';
| `onFocus?` | `React.FocusEventHandler<HTMLElement>` | - | Действие по фокусу |
| `onBlur?` | `React.FocusEventHandler<HTMLElement>` | - | Действие при потере фокуса |
| `autoComplete?` | [`AutoCompete`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) | - | Автозаполнение поля ввода — аналог HTML-атрибута [`autocomplete`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) |
| `onClear?` | `React.MouseEventHandler<HTMLButtonElement>` | - | Функция, которая определяет, как будет удалено значение из поля |
| `onChange?` | `(value: string`<code>&#124;</code>`null, params: {e: React.ChangeEvent; id?: string, number; name?: string; }) => void;` | - | Действие при изменении текстового поля |
| `className?` | `string` | - | Дополнительный CSS-класс |
| `inputRef?` | `React.Ref<HTMLTextAreaElement` <code>&#124;</code> `HTMLInputElement>` | - | Ссылка на DOM-элемент поля ввода |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export const TextFieldExampleMaskSetValue = () => {
placeholder="+7(999)999-99-99"
inputRef={ref}
defaultValue={defaultValue}
withClearButton
onClear={() => setValue('')}
/>
<Button
iconLeft={IconRevert}
Expand Down
1 change: 1 addition & 0 deletions src/components/TextField/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export type TextFieldProps<TYPE extends string> = PropsWithHTMLAttributes<
onKeyUp?: React.KeyboardEventHandler;
onKeyUpCapture?: React.KeyboardEventHandler;
onKeyDown?: React.KeyboardEventHandler;
onClear?: React.MouseEventHandler<HTMLButtonElement>;
},
HTMLDivElement
> &
Expand Down

0 comments on commit 986cdac

Please sign in to comment.