Skip to content

(PDS-511) Bugfix for autocomplete select not staying open when typing #381

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

Merged
merged 1 commit into from
Feb 10, 2021

Conversation

jilliankeenan
Copy link
Contributor

@jilliankeenan jilliankeenan commented Feb 9, 2021

Previously In the open prop if you supply the boolean value true what we would expect to see is the autocomplete dropdown open the entire time - we are not seeing that it seems that is being ignored.

This PR resolves this issue and fixes the Autocomplete Select dropdown not staying open when it is uncontrolled (for example when being consumed by a form this is where the bug was first noticed).

How to test using Styleguidist

Navigate to FORM -> Uncontrolled paste the following markdown.


const movieOptions = [
  { value: 'american-treasure', label: 'American Treasure' },
  { value: 'ghost-rider', label: 'Ghost Rider' },
  { value: 'point_break', label: 'Point Break' },
];

const initialValues = {
  controlledFirstName: 'Sponge',
  controlledLastName: 'Bob',
  controlledPassword: '',
  controlledFavoriteMovie: '',
  controlledNotARobot: false,
};

/** Mock api call method */
const submitForm = values => values;

class MyPage extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      values: initialValues,
      submitting: false,
      filteredOptions: [],
    };

    this.onSubmit = this.onSubmit.bind(this);
    this.handleFactValueFilter = this.handleFactValueFilter.bind(this);
  }

  onSubmit(values) {
    this.setState({ submitting: true });

    submitForm(values);

    this.setState({ submitting: false, values });
  }

  handleFactValueFilter(searchTerm) {
    const newFilteredFacts = movieOptions.filter(listOptions => {
      return listOptions.value.toLowerCase().includes(searchTerm.toLowerCase());
    });
    this.setState({ filteredOptions: newFilteredFacts });
  }

  render() {
    const { values, submitting, filteredOptions } = this.state;

    return (
      <Form
        submittable
        cancellable
        initialValues={values}
        submitting={submitting}
        onSubmit={this.onSubmit}
      >
        <Form.Field
          type="text"
          name="controlledFirstName"
          autoComplete="firstname"
          label="First name"
          placeholder="Enter your first name..."
        />
        <Form.Field
          type="text"
          name="controlledLastName"
          autoComplete="lastname"
          label="Last name"
          placeholder="Enter your last name..."
        />
        <Form.Field
          type="password"
          autoComplete="current-password"
          name="controlledPassword"
          label="Password"
          placeholder="Enter your password..."
          description="Please enter your password"
          error="You goofed up now"
        />
        <Form.Field
          type="autocomplete"
          name="controlledFavoriteMovie"
          label="favorite movie"
          placeholder="Choose a movie"
          options={filteredOptions}
          open={filteredOptions.length > 0}
          onFilter={this.handleFactValueFilter}
        />
        <Form.Field
          type="checkbox"
          name="controlledNotARobot"
          label="Not a robot"
          description="Are you a human?"
        />
      </Form>
    );
  }
}

BUG BEHAVIOUR

2021-02-09 17 33 38

… in uncontrolled

Previously In the open prop if you supply the boolean value true what we would expect to see is the autocomplete dropdown open the entire time - we are not seeing that it seems that is being ignored. This PR resolves this issue and fixes the Autocomplete Select dropdown not staying open when it is uncontrolled (for example when being consumed by a form).
@jilliankeenan jilliankeenan requested a review from a team as a code owner February 9, 2021 17:32
Copy link
Contributor

@chrisleicester chrisleicester left a comment

Choose a reason for hiding this comment

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

Great work tracking this down! I thought this whole time it was just weird, expected behavior.

@vine77 vine77 merged commit bdee43e into puppetlabs:development Feb 10, 2021
@vine77 vine77 mentioned this pull request Feb 10, 2021
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 this pull request may close these issues.

3 participants