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

feat(TextField): add onClear #3593

Merged
merged 2 commits into from
Apr 3, 2024
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
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
Loading