Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

[Web Portal] AutoComplete component #2887

Merged
merged 2 commits into from
Jun 10, 2019
Merged

[Web Portal] AutoComplete component #2887

merged 2 commits into from
Jun 10, 2019

Conversation

sunqinzheng
Copy link
Contributor

@sunqinzheng sunqinzheng commented Jun 5, 2019

What's this?

The AutoComplete is an extension of a regular text-field that will auto-complete the input dynamically.

The difference between AutoComplete and ComboBox is that it is mainly focused on text input.

Props

  • items
    • string[], required
    • Array of suggestions. Only suggestions prefixed by current text field value are displayed by default.
  • value
    • string, required
    • TextField's value
  • onChange
    • callback function, required
      • (newValue: string) => {}
    • TextField's onChange function
  • showAllSuggestions
    • boolean, required
    • Whether to disable suggestions' default prefix filter.

Example

const app = () => {
  const [val, setVal] = useState('');
  return (
    <AutoComplete
      value={val}
      onChange={setVal}
      items={['pen', 'apple', 'applepen']}
    />
  );
}

@coveralls
Copy link

Coverage Status

Coverage remained the same at 53.218% when pulling 2540302 on qinsu/portal/ac into 1064bf2 on master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 53.218% when pulling 2540302 on qinsu/portal/ac into 1064bf2 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 53.218% when pulling 2540302 on qinsu/portal/ac into 1064bf2 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 53.218% when pulling 2540302 on qinsu/portal/ac into 1064bf2 on master.

[spacing],
);
// suggestions
useEffect(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give a simple example about how to use it?
And the auotComplete can support only autocomplete the last word? For example I have a sentence: "May the force be with you", and I input "May the fo", the suggestion should be "May the force".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AutoComplete component behaves like a combo box. So you need to provide the whole sentence "May the force".
Since the value and suggestionItems are controlled by its parent, you can add your own suggestion logic.
e.g. add "May the force" option only when user has input "May the f"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want a multiline word/phrase level AutoComplete component, I recommend you use Monaco Editor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks for the explanation.

@debuggy debuggy mentioned this pull request Jun 6, 2019
13 tasks
@sunqinzheng sunqinzheng merged commit 68e10b8 into master Jun 10, 2019
@sunqinzheng sunqinzheng deleted the qinsu/portal/ac branch June 10, 2019 04:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants