WIP: Autocomplete component - #190
danseethaler wants to merge 10 commits into
Conversation
|
|
||
| return ( | ||
| <Downshift | ||
| onStateChange={({ inputValue, ...rest }) => { |
There was a problem hiding this comment.
sooo nice ;)... render props are so powerful!
| <InputGroup> | ||
| <AutoCompleteInput | ||
| onKeyPress={e => { | ||
| const TAB_KEY = 9; |
There was a problem hiding this comment.
maybe we can go ahead and move these to common/helpers.js ? export const KEY_CODES = { TAB_KEY: 9, ... }
There was a problem hiding this comment.
I wish there was a way to destructure the properties but I like having them in the common folder.
There was a problem hiding this comment.
Nice @danseethaler 👍
While reviewing, I was surprised to see the show info button was disappeared from your storybook 😕
|
|
||
| export const noop = Function.prototype; | ||
|
|
||
| export const KEY_CODES = { TAB_KEY: 9, ENTER_KEY: 13 }; |
There was a problem hiding this comment.
Is it really common?
If not, it should live under AutoComplete/constants.js
tbh, I'm not sure but let agree the first one outside of the autocomplete scope that wants to use it, will just move it into common/helpers?
Check out how the Alert is using inner helpers and constants:
https://github.com/patternfly/patternfly-react/tree/master/src/components/Alert
There was a problem hiding this comment.
keyboard key codes will be used very often when implementing a11y from a JS standpoint. it's mostly about handling enter press/escape press/tab press from the JS side...so for that reason, i would propose keeping it common to all.
| import AutoCompleteItems from './AutoCompleteItems'; | ||
| import { KEY_CODES } from '../../common/helpers'; | ||
|
|
||
| export const getActiveItems = items => |
There was a problem hiding this comment.
It should move into AutoComplete/helpers.js, see how it works in the Alert component:
https://github.com/patternfly/patternfly-react/tree/master/src/components/Alert
|
|
||
| return ( | ||
| <Downshift | ||
| onStateChange={({ inputValue, ...rest }) => { |
There was a problem hiding this comment.
Let's try to keep this method lean.
Can you move this method into this.handleStateChange?
There was a problem hiding this comment.
I like abstracting like that when possible. The extra challenge here is needed the onInputUpdate function in the scope. We could forward it through by currying or something but I think it's easier to see inline.
There was a problem hiding this comment.
It's a prop, it should always be available under, this.props
| selectedItem={this.state.inputValue} | ||
| {...rest} | ||
| > | ||
| {({ |
There was a problem hiding this comment.
It just looks really weird to pass a method as children in react JSX.
Downshift API support a render prop that can be used instead, I think it would feel better.
There was a problem hiding this comment.
Yeah I'm totally open on this concept. It's just a preference since Downshift supports both. I'll change it and we'll take a look!
There was a problem hiding this comment.
Having a render prop sounds interesting, as it would allow us to customize the options (e.g. think you would like to add an avatar in the user dropdown)
There was a problem hiding this comment.
@ohadlevy yeah that's exactly the idea here. This implementation is pushing for a standardized auto-complete using the MenuItem component with just text but Downshift can be used to compose any kind of dropdown interface you want.
There was a problem hiding this comment.
yep... render prop vs children as a function is just semantics i believe... either is fine w/ me 👍 ... i see people posting polls about this lol
| {labelText && <label {...getLabelProps()}>{labelText}</label>} | ||
| <InputGroup> | ||
| <AutoCompleteInput | ||
| onKeyPress={e => { |
There was a problem hiding this comment.
Let's try to keep this method lean.
Can you move this method into this.handleKeyPress?
There was a problem hiding this comment.
Same thing here with all the closure scope we need. It would be nice to isolate but I don't see how without forward a bunch of variables which I'm not a fan of.
There was a problem hiding this comment.
yea... that is one thing that appears different about render props... the scope is different. I was noticing the same a bit back in the Wizard and it was hitting my brain. I think you can bind it if you want, but it's not as clean.
There was a problem hiding this comment.
Yeah I'm not a fan of binding in this context. I think it's easier to see what's happening inline even though it's long.
| } | ||
|
|
||
| AutoComplete.propTypes = { | ||
| items: PropTypes.arrayOf(PropTypes.object).isRequired, |
There was a problem hiding this comment.
Can you also add a description comment?
Checkout the Alert propTypes:
https://github.com/patternfly/patternfly-react/blob/master/src/components/Alert/Alert.js#L38
And how they compiled into the storybook:
https://rawgit.com/patternfly/patternfly-react/gh-pages/index.html?selectedKind=Alert&selectedStory=Alert%20types&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybooks%2Fstorybook-addon-knobs
Click "show info" and scroll down to the prop types description.
There was a problem hiding this comment.
Wow that's cool! Thanks for sharing 👍 Added them in now.
| @@ -0,0 +1,54 @@ | |||
| /* eslint-disable no-alert */ | |||
There was a problem hiding this comment.
Yeah guess this was an issue the foreman lint config but not a problem here. Good catch!
| </Col> | ||
| </Row> | ||
| </div> | ||
| )) |
There was a problem hiding this comment.
Really need this decorator?
There was a problem hiding this comment.
The main purpose of this is to show how the dropdown will stick to the input field regardless of where it is on the screen.
There was a problem hiding this comment.
I still don't understand why the general design won't address this need.
| this.ref && this.ref.removeEventListener('keydown', this.handeKeyPress); | ||
| } | ||
|
|
||
| handeKeyPress = e => { |
There was a problem hiding this comment.
Your english is better than mine 👋
|
|
||
| return ( | ||
| <MenuItem | ||
| {...getItemProps({ |
There was a problem hiding this comment.
I think it would be more readable as a separate var
const itemProps = getItemProps({ ... });
<MenuItem {...itemProps}>{text}</MenuItem>;
sharvit
left a comment
There was a problem hiding this comment.
Looks much better,
I think it is very important to show a storybook with documentation.
Right now, if I am getting into the storybook, I have no information about how to use it in my project.
|
|
||
| return ( | ||
| <Downshift | ||
| onStateChange={({ inputValue, ...rest }) => { |
There was a problem hiding this comment.
It's a prop, it should always be available under, this.props
| </Col> | ||
| </Row> | ||
| </div> | ||
| )) |
There was a problem hiding this comment.
I still don't understand why the general design won't address this need.
|
Thanks for the tips on the storybook info @sharvit. I haven't used that before so I patterned my info on the Also open to other thoughts/reviews! There is a new discussion in pf-design linked above that's worth checking out. |
14487e1 to
f399287
Compare
sharvit
left a comment
There was a problem hiding this comment.
Awesome, Thanks @danseethaler
One last minor issue with the AutoComplete class and I am really happy with the result here 👍
| {labelText && <label {...getLabelProps()}>{labelText}</label>} | ||
| <InputGroup> | ||
| <AutoCompleteInput | ||
| onKeyPress={e => { |
There was a problem hiding this comment.
Can you move this function to be apart of the class like you did with handleStateChange?
There was a problem hiding this comment.
Unfortunately we don't have the render prop props (say that three times fast :) in a class function so we'd have to do some pass-throughs which I'm not a fan of.
There was a problem hiding this comment.
Cool, I understand your point now, it will actually be really messy...
|
@danseethaler Can you also redeploy the storybook? |
| withInfo({ | ||
| source: false, | ||
| propTables: [AutoComplete], | ||
| propTablesExclude: [MockAutoComplete], |
There was a problem hiding this comment.
@priley86 This approach can fix some problems we are facing with the storybook?
@gilad215 /cc
There was a problem hiding this comment.
👍 yes - that is the suggestion right now... nice job.
sharvit
left a comment
There was a problem hiding this comment.
Thanks @danseethaler, Feels really good 👍
| selectedItem | ||
| }) => ( | ||
| <Dropdown.Menu | ||
| style={{ |
There was a problem hiding this comment.
@priley86 while we're waiting for a pf-design for this component - is there a particular way we want to handle styling so it's not inline? I don't see any .scss files except at the top level to import pf core styles.
There was a problem hiding this comment.
@danseethaler i've just been adding them here in the sass directory while demonstrating them in my PRs (then we can review it here first and consider adding it to PF Core after as a subsequent PR). Make sense? I believe @jgiardino is further detailing how to do this in #195
There was a problem hiding this comment.
@priley86 ah perfect. I'll update accordingly.
d554026 to
40a366b
Compare
40a366b to
d077833
Compare
|
@danseethaler is it still WIP? |
|
Hi @danseethaler . Awesome component 👍 . I used jquery version of autocomplete. I think Bootstrap-3-Typeahead and typeahead.js will give you inspirations if you want to add interesting features. |
|
@LaViro any chance you can take over this component? sadly I don't that @danseethaler will complete it in the near future :) thanks! |
|
@ohadlevy, sure.. I will do my best to (auto)complete this :) |
affects: patternfly-react ISSUES CLOSED: patternfly#190 patternfly#281

What:
Adding a proposed auto-complete component. This component will show a dropdown of items while a user is typing. The items in the dropdown list are managed outside of the auto-complete component. The component implements the visual rendering of the items as well as keyboard support (tab, up, down, enter) and a11y accessibility. This component supports disabled items, headers, and dividers.
This is still a WIP and additional discussion is had in #189.
Link to Storybook:
https://rawgit.com/danseethaler/patternfly-react/autocomplete-component-storybook/index.html?selectedKind=AutoComplete&selectedStory=AutoComplete&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybooks%2Fstorybook-addon-knobs
Additional issues:
Fixes #189