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

Fix #1260 Updated search-bar input to allow autocomplete #1387

Conversation

MSTEWARDSON
Copy link
Contributor

Issue This PR Addresses

Issue #1260

Type of Change

  • Bugfix: Change which fixes an issue
  • New Feature: Change which adds functionality
  • Documentation Update: Change which improves documentation
  • UI: Change which improves UI

Description

Changed the search-bars input field to allow autocomplete from a given data set. Addition css was added to get the new input to match the previous style, all old functionality seems to be intact.

Currently it is not linked to a data set, but I am planning to open another issue to add the backend support needed after this.

To test the code you can add some options to the data list, when done they should appear below the search bar as you type.

Checklist

  • Quality: This PR builds and passes our npm test and works locally
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not (if applicable)
  • Documentation: This PR includes updated/added documentation to user exposed functionality or configuration variables are added/changed or an explanation of why it does not(if applicable)

@c3ho
Copy link
Contributor

c3ho commented Nov 17, 2020

Why was the previous one closed?

@MSTEWARDSON
Copy link
Contributor Author

I had an issue with merge conflicts that I couldn't resolve. I asked humphd if it was ok to make a new PR in this case. Sorry for the confusion.

<option>Test 2</option>
<option>Test 3</option>
</datalist>
<datalist id="searchData"></datalist>
Copy link
Contributor

Choose a reason for hiding this comment

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

To do this properly, we're going to want to only apply the new datalist (and eventually fetch its data) if the user selects an Author filter. The easiest way to achieve this is to use the filter value in order to decide whether or not to render this. Another way to go would be to break this part of the search UI into its own components:

<SearchInput filter={filter} />

And the SearchInput.jsx could do something like this:

function AuthorSearchInput() {
  return (
    <>
      <input 
         //...rest of props here
          list="searchData"
      />
      <datalist id="searchData">...</datalist>
    </>
  );
}

function PostSearchInput() {
  return <input ... />
}

function SeachInput({ filter }) {
   return filter === 'author' ? <AuthorSearchInput /> : <PostSearchInput />;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I think I see where your going here. What is the purpose of PostSearchInput() in this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Where AuthorSearchInput includes a <datalist> and a list="..." attribute, PostSearchInput does not: it only returns the <input ...> where ... is all of the attributes I didn't bother typing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh wait never mind, it would just be the output for a non autocomplete input.

Copy link
Contributor

Choose a reason for hiding this comment

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

Exactly, and if you want, it could be what it is now vs being limited to what you had to do to get the datalist to work (i.e., they can use different components/elements to render the input).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@humphd

I have the jsx page setup and I can now switch between the two different author and post inputs. I'm now trying to figure out how make both these inputs to activate the SearchPage portion of the site.

Here's were I call my SearchInput.jsx providing the filter.

<FormControl fullWidth={true}>
              <SearchInput filter={filter} />
</FormControl>

And then here's my AuthorSearchInput():

function AuthorSearchInput(props) {
  const classes = useStyles();
  const { searchText, onChangeHandler } = props;

  const onTextChange = (event) => {
    onChangeHandler(event.target.value);
  };

  return (
    <>
      <input
        // ...rest of props here
        type="text"
        id="authorSearch"
        className={classes.input}
        placeholder="How to Get Started in Open Source"
        variant="outlined"
        list="searchData"
        value={searchText}
        onChange={(event) => onTextChange(event)}
        inputProps={{ 'aria-label': 'search telescope' }}
      />
      <datalist id="searchData">
        <option>Test 1</option>
        <option>Test 2</option>
        <option>Test 3</option>
      </datalist>
    </>
  );
}

Within my SearchInput.jsx I can't seem to be able to use onChange={(event) => onTextChange(event)}
This throws an error that it is undefined. I'm unsure on how to get this working.

Comment on lines +34 to +48
'&:hover': {
border: '2px solid #E5E5E5',
},
'&:focus': {
border: '2px solid #333E64',
},
'& > *': {
fontSize: '1.6rem !important',
color: theme.palette.text.default,
},
height: '50px',
height: '55px',
backgroundColor: '#E5E5E5',
paddingLeft: '10px',
border: '1px solid #A0A0A0',
borderRadius: '5px',
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to use our colour palette?.

See how it was done in other components, like here or here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep I'm switching over to using the palette now.

@MSTEWARDSON MSTEWARDSON merged commit 9ddb846 into Seneca-CDOT:issue-1260/mstewardson Nov 18, 2020
@MSTEWARDSON
Copy link
Contributor Author

Can someone help my out here. I was trying to push my changes up to add to this PR so I could have someone look at my code. But when I made my push it merged and closed the branch? Im confused now.

@humphd
Copy link
Contributor

humphd commented Nov 18, 2020

@MSTEWARDSON I'm not clear what you've done here: MSTEWARDSON merged commit 9ddb846 into Seneca-CDOT:issue-1260/mstewardson 5 hours ago.

I think you need to start a new branch off of current master and add your changes, then create a new PR.

@MSTEWARDSON
Copy link
Contributor Author

Yeah I just made sure my master was up to date and am currently making a new branch.

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.

4 participants