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

Autosuggest option values not working properly #1416

Closed
aidamag opened this issue Dec 12, 2022 · 1 comment · Fixed by #1443
Closed

Autosuggest option values not working properly #1416

aidamag opened this issue Dec 12, 2022 · 1 comment · Fixed by #1443
Assignees
Labels
bug Something isn't working jira This task is referenced in a story of Jira

Comments

@aidamag
Copy link
Contributor

aidamag commented Dec 12, 2022

Describe the bug
Writing certain strings in the autosuggest will show error because we are converting the value into a regular expression inside the component.

If we write for example *, the value of the autosuggest will be converted to regex. Because * is a wrong regular expression it will show this error.

To Reproduce

  1. Create a new React App using create-react-app.
  2. Install the @dxc-technology\halstack-react dependencies and run the app.
  3. Write the following example:
  const countries = ["*", "Albania"];
  const [value, setValue] = useState("");
  const onChange = ({ value }) => {
    setValue(value);
  };
  const onBlur = ({ value }) => {
    setValue(value);
  };

  const callbackFunc = (newValue) => {
    const result = new Promise((resolve) =>
      setTimeout(() => {
        resolve(
          newValue
            ? countries.filter((option) =>
                option.toUpperCase().includes(newValue.toUpperCase())
              )
            : countries
        );
      }, 1500)
    );
    return result;
  };
  return (
    <DxcInset space="2rem">
      <DxcTextInput
        label="Enter your country"
        value={value}
        onChange={onChange}
        suggestions={callbackFunc}
        onBlur={onBlur}
      />
    </DxcInset>
  );
  1. Click the component and select the option *.
  2. See the error.

Expected behaviour
It should select the option.

Screenshots
image

image

image

image

Add labels
Text input, autosuggest.

@aidamag aidamag added bug Something isn't working jira This task is referenced in a story of Jira labels Dec 12, 2022
@aidamag aidamag self-assigned this Dec 12, 2022
@hanoj-budime
Copy link

Thanks for following up this #1414 issue.

@lisa159

@aidamag aidamag removed their assignment Dec 16, 2022
@aidamag aidamag self-assigned this Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working jira This task is referenced in a story of Jira
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants