-
Notifications
You must be signed in to change notification settings - Fork 530
Public API: The Basics #138
Comments
/cc @sprjr |
Aye, I'm not even sure how to do this entirely. I think our goal should be to only render two things: 1) <Autocomplete wrapper={MyComponent} {...rest} />
<Autocomplete {...props}>
<MyComponent />
</Autocomplete> This might allow us to avoid
Agreed. The simpler our API, the better. It might even be nice if we identify the props required by Autocomplete that are not native, and only expose those in
I think that we've grown the props list by simply adding props to fix problems, and not thinking about fixing the problems and then adding props to help with that. I'm all aboard in terms of simplifying that list and making it easier to reason about and interact with for sure. |
I just wanted to mention that, as a user of react-autocomplete, the issue description here has been incredibly useful! |
@CMTegner maybe this should be in the README, I keep coming back here 😁 |
What's the status of this issue? Any roadmap for the improvements detailed in the original message? I'm currently developing an application and resorting to some extremely "hacky" workarounds because I can't set a custom onBlur as a prop. I'd be happy to help implement some of these changes as well — this component is already great in so many ways, it just needs that extra push. 😊 |
Hey Paulo, thanks for the offer to help out - more than happy to review a PR. Would rather that than you having to write very hacky code in your code. Currently looking to ship @CMTegner's other PR soon - not sure if that behavior would help your situation out. For onBlur, is it not possible to pass it via inputProps any more? Not in front of the latest API currently so I could be wrong. Feel free to send code this way if you'd like and we can get the polish/improve items shipped with you! Sent from my iPhone
|
Thanks for the reply, @sprjr!
Looking at the current code, it doesn't seem possible: <input
{...this.props.inputProps}
role="combobox"
aria-autocomplete="list"
autoComplete="off"
ref="input"
onFocus={this.handleInputFocus}
onBlur={this.handleInputBlur}
onChange={(event) => this.handleChange(event)}
onKeyDown={(event) => this.handleKeyDown(event)}
onKeyUp={(event) => this.handleKeyUp(event)}
onClick={this.handleInputClick}
value={this.props.value} /> If you pass onFocus, onBlur, onChange, etc. via inputProps they'll be ignored because the component is already setting those events, right? #54 already handled this issue as well as I can think of, but that PR has been closed because "it'll likely be superseded shortly by the work that will be spun off as a part of #138." So I'm guessing @CMTegner probably had some other ideas as for how to handle this issue? |
@pcalves I've just started work on implementing my ideas, hopefully the work will materialise as a PR within next week. It will of course be a breaking change, so we may want to plan a few other things before we do a major release. I'll see if have time tomorrow to extract the code which prevents clobbering the event handlers passed via In the meantime, have a look at #163 and see if it's at all relevant to your situation. |
@pcalves ah yea, forgot there were overrides below it for that prop. My mistake! |
#165 contains some of the work described here. |
I have a WIP branch here with some of the proposed changes.
I settled on <div style={{ display: 'inline-block' }} {...props.wrapperProps}>
<input />
<Menu />
</div> There's no elegant way of removing
I chose
This was easy: just pass everything to
There's currently no elegant way of doing this. What I've implemented is a solution which proxies all (minus browser-specific ones) of What I actually want is facebook/react#4213. Having something like You can mimic this behaviour by supporting a callback which receives the I'd like some input on this from anyone who has an opinion or experience with the matter. That's as far as I've gotten. I intend to continue work and deal with point no. 4 in the coming days. All of this work will naturally lead to quite a few breaking changes, so I plan on overhauling the menu/item presentation API (which will likely also deal with the default menu styles) while I'm at it. |
is there a sane default for shouldItemRender? A basic searching algorithm? |
@davis |
@CMTegner i feel like a group of nicer defaults like "caseSensitiveMatch" "caseInsenstitiveMatch" etc could be nice. you could allow the user to just provide a function that 'gets' the value that should be compared (totally a feature request) |
@davis yes, that would be very nice. Having a set of curated, frequently used/desired behaviours that allow out-of-the-box use is great for users that have basic requirements. That being said, I don't necessarily think that it would belong in this module. What we're aiming for first and foremost is to create a set of solid APIs that allow others (the application developer or other module creators) to build atop of. For example, it is fairly easy to create a component that wraps class MyAutocomplete extends Component {
propTypes = {
match: PropTypes.oneOf(['begin', 'any'])
}
startsWith (item, value) { return item.indexOf(value) === 0 }
anywhere (item, value) { return item.indexOf(value) > -1 }
render () {
return (
<Autocomplete
items={this.props.items}
shouldItemRender={this.props.match === 'begin' ? this.startWith : this.anywhere}
...
/>
)
}
} Start adding other props like |
cannot figure out how to add className to
is not working for me on current version never mind this works → |
Hi @ahmadie! You're probably looking for |
can anyone please share the detailed code to increase the input box size |
I was wondering how the |
tl;dr: We want to make
Autocomplete
's public API better, and we need your input!Current API, for reference:
Some thoughts on the current API:
wrapperProps
andwrapperStyle
are the main culprits. There is a way to do away with the wrapper entirely - by rendering the menu as a new React tree - but that brings with it extra bookkeeping and logic that we may not want to have to deal with in the long run. It also prevents relative-positioning of the menu, which is only possible when the menu is a child of the same node as the<input>
.Autocomplete
is an augmented<input>
field, and use existing knowledge of the native input controls to quickly configure it. Passingvalue
,onChange
,className
,placeholder
, etc, should just work like it does on a<input>
element. Currently the native<input>
props are "hidden" behindinputProps
, while only theAutocomplete
-specific props are exposed as top-level props.Autocomplete
to behave and react like a native<input>
element. Callinginstance.focus()
should focus the input, andinstance.select()
should select any text in the input.onFocus
andonBlur
should be triggered accordingly, as well as any other native event. Arrow keys should navigate text, and return should submit any surrounding form. The consumer shouldn't have to consider tradeoffs when choosingAutocomplete
, it should be purely additive.shouldItemRender
,sortItems
, and howString#indexOf
is used to determine matches inmaybeAutoCompleteText
should maybe not be of a concern toAutocomplete
. We did a big improvement by movingvalue
out of state, and I think we can further improve by handing more responsibility to the consumer.In my mind
Autocomplete
is this:An
<input>
field with typeahead support and the ability to render an accessible list of options with keyboard and mouse navigation.I keep this in the back of my mind because it helps me focus on what
Autocomplete
should be doing above all else.I suggest - to get started - that we pass all top-level props to the wrapped
<input>
(minus the ones that areAutocomplete
specific, naturally), and thus removinginputProps
. This also includes ensuring that any event handler passed in (onBlur
,onClick
, etc) are attached correctly, even if we use them internally.Next, I suggest adding all instance methods which one would expect to find on a
<input>
, e.g.focus
,select
,blur
, etc..I'll leave this issue open for a bit before we start any work. Hopefully we can get a discussion going to ensure we're heading down the correct path.
The text was updated successfully, but these errors were encountered: