-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
RFC: all event handlers should callback with (event, data) #623
Comments
@craig1123 Your timing was impeccable here, I was just suggesting to the team here that we should always pass I think this is useful and we should consider making it a library feature, and not just add it to this one component for this one handler. I'll leave it at that for now and suggest we start looking at how to achieve this consistently. Ideas welcomed. |
LGTM, I think we need there list of components with such events and update them all. |
This is a living spec open to changes, feel free to comment for changes. 💬 New Callback ParametersUse
|
I think we should keep the order of the arguments as-is, mainly because it would create inconsistency between events we handle and events we don't. This would be the required usage with the argument order change: handleClick(event)
handleChange(data, event)
<Input onClick={handleClick} onChange={handleChange} /> This feels weird to me. We could get around this by handling all events and always calling handlers with |
I'm of the mind all signatures should be consistent. So given: <Input onClick={handleClick} onChange={handleChange} /> Callbacks would be either: handleClick(data, e)
handleChange(data, e)
// or
handleClick(e, data)
handleChange(e, data) My initial thought is that the This gives me another idea, we have a single object that included the event: handleChange({ event, ...data })
// e.g { event: [SyntheticEvent], value: 'hello' } |
I 100% agree signatures should be consistent.
I'm not actually talking about callbacks where we (SUI-React) wouldn't pass back data. I'm talking about all the events that we don't explicitly handle for a given component. For example, the only event-related prop So if we change the arguments, when the
This means I would need different signatures for each callback depending on if it's passed through to React or not. With the other idea you mentioned handleClick(event) {
const { target } = event
}
handleChange({ event })
const { target } = event
} I could see possibly spreading data into the event: // Input.js
onChange({ ...event, this.props })
// handler
handleChange(event) {
event.preventDefault()
const { name, value } = event
} Although tbh I think is the best option is @layershifter - would love your thoughts here as well 😄 |
I see. The only way around that would be to intercept all events and rearg them, which is a bit ridiculous. I'll update the spec, removing the reorder proposal. We'll have 100% consistency in the signatures, though the presence of the arguments themselves will be inconsistent. We may want to consider using |
I've updated the spec, removing reversed args, we'll call that the final spec. 👍 |
There are actually still some components open on that list. I'll reopen this, update those, and close it with a new PR. |
Going back to my initial question before this is closed, is there an onMouseEnterOption prop (or some event handler for hovering over options) for the dropdown? |
@craig1123 you should be able to pass any valid React prop as an object key/value pair to the options. Each option object is used as a props object to each |
Hi, I have a simple enhancement to propose.
It would be nice to have access to the options of a Dropdown using the
onMouseEnter
handler. There is obviously already anonChange
handler which allows me to execute some function when I select an option, but I want to hover over the items as well, triggering some function.Thanks, I really enjoy working with stardust.
The text was updated successfully, but these errors were encountered: