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

TextInput should emit complete SyntheticEvent with clear input action #129

Closed
adrian-potepa opened this issue Feb 28, 2024 · 0 comments · Fixed by #130
Closed

TextInput should emit complete SyntheticEvent with clear input action #129

adrian-potepa opened this issue Feb 28, 2024 · 0 comments · Fixed by #130
Assignees

Comments

@adrian-potepa
Copy link
Collaborator

const handleOnClear: MouseEventHandler<HTMLButtonElement> =
useCallback(() => {
setInnerValue('');
onChange?.({
target: { value: '' },
} as ChangeEvent<HTMLInputElement>);
}, [onChange]);

Possible resolve:

const handleOnClear: MouseEventHandler<HTMLButtonElement> = () => {
    setInnerValue('');

    const input = containerRef.current?.querySelector('input');

    if (!input) return;

    const setter = Object.getOwnPropertyDescriptor(
      input.constructor.prototype,
      'value',
    )?.set;

    if (!setter) return;

    setter.call(input, '');

    const e = new Event('input', { bubbles: true });
    input.dispatchEvent(e);
  };
@adrian-potepa adrian-potepa self-assigned this Mar 25, 2024
@adrian-potepa adrian-potepa linked a pull request Mar 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant