Button with endEnhancer onClick issue
See original GitHub issueCurrent Behavior
I have a Button
which has an endEnhancer, to show an icon. The button has an onClick
event to update a state. If I click the button itself, then it will set the value
of the Button
no problem.
If I click the endEnhancer icon, then it will still run the onClick
event from the button, but it the value will be undefined
.
What is the correct use of this combo or is there a bug when using an endEnhancer? Should it not inherit the value
of the button, if it inherits the onClick
event?
Here’s a demo with an alert. Try clicking the button and precisely on the icon: https://codesandbox.io/s/button-with-endenhancer-doxgi
Expected Behavior
That clicking the button itself or the endEnhancer produces the same event / outcome.
Your Environment
Tech | Version |
---|---|
Base UI | v8.6.1 |
React | 16.8.2 |
browser | Chrome 75.x |
- I have searched the issues of this repository and believe that this is not a duplicate.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Problem with attaching onClick event to dynamically created ...
The issue is not with the pagination buttons but the buttons in the list items that fire all at once when clicked. Its...
Read more >How to use the baseui/button.KIND.secondary function in baseui ...
To help you get started, we've selected a few baseui/button. ... Snyk Code to scan source code in minutes - no build needed...
Read more >Cheat Sheet - Base Web
button -group · ButtonGroupProps · ariaLabel; children · disabled · mode · onClick · overrides · selected · shape · size · kind...
Read more >trying to pass "id" onclick of a button in LWC [closed]
Questions about implementation problems need to include a specific description of the problem (including exact errors and stack traces, if any) ...
Read more >@biossun/react-view - NPM Package Overview - Socket - Socket.dev
onClick : { value: '() => alert("click")', type: PropTypes.Function, description: 'Function called when button is clicked.', }, disabled: { value: false ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is how event capturing & bubbling works by default in the browser.
I don’t think we should change/hide this behavior. There may be legitimate use cases for allowing normal event capturing within an enhancer (a nested checkbox perhaps). The
onClick
still has context on which button was clicked so I don’t think this behavior limits folks. If you do need to grab something from the button element instance related to the event, you can always use the event object to grab the parent element or use a ref.While I don’t think the actual event should be altered/hidden, the
onChange
handler itself might pass additional arguments that could be useful. We don’t have to only pass events.This issue is stale because it has been open 30 days with no activity. If it’s still valid, please remove the stale label or comment on the issue, otherwise this ticket will be closed in 5 days