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

Provide different modes of submission #80

Open
takecare opened this issue Aug 9, 2023 · 0 comments
Open

Provide different modes of submission #80

takecare opened this issue Aug 9, 2023 · 0 comments

Comments

@takecare
Copy link

takecare commented Aug 9, 2023

Some apps might want to use this component to allow users to enter multi-line text. Right now this is not easily achieved as enter is hard-coded to be the "submission key".

My question/proposal would be to add an optional prop that would define what is a submission. Something like the following:

export type Props = {
  // ...

  /**
  * Function that determines if a key press constitutes a submission (which will result in `onSubmit` being called)
  */
  readonly isSubmit?: (key: Key) => boolean;

  // ...
};

function TextInput({
  value: originalValue,
  placeholder = '',
  focus = true,
  mask,
  highlightPastedText = false,
  showCursor = true,
  onChange,
  isSubmit = key => key.return,
  onSubmit
}: Props) {

  // ...

  useInput(
    (input, key) => {
      // ...
      if (isSubmit(key) && onSubmit) {
        onSubmit(originalValue);
	return;
      }
      // ...
  );
  
  // ...
};

This would allow for apps to support multiple-line input, defining what they consider to be the submission (e.g. 3 new lines in a row), all the while being backwards compatible.

Please let me know your thoughts and I can open a PR with the changes.

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

No branches or pull requests

1 participant