Comments (6)
ENG-1079 [BUG] - <Button> onClick handler is not triggered by keyboard
from nextui.
I am working on it.
from nextui.
NextUI Version
2.4.2 and @nextui-org/[email protected]
Describe the bug
onClick
handler is not triggered when activating<Button>
with keyboard. This behavior isn't unique to buttons and happens on some other components (checkbox, switch)Your Example Website or App
https://broken-nextui-components.vercel.app/ Source code for example: https://github.com/Inbestigator/broken-nextui-components
Steps to Reproduce the Bug or Issue
- Go to any page with component.
- Set focus on (for example, by tabbing).
- Press Spacebar or Enter key.
- onClick handler is not triggered, however button shows ":active" state.
Expected behavior
onClick
handler is triggered as it normally happens for<button>
element in React.Screenshots or Videos
No response
Operating System Version
Windows
Browser
Chrome and Firefox
The Bug is very simple to solve,
you have used onClick()
method, which requires element to be clicked, that is why no action on hitting Enter/ Space
key
<Button onClick={() => alert("Clicked")}>Button</Button>
You need to use onPress()
method, which support key presses, hence for action through keyboard key
Use this
<Button onPress={() => alert("Clicked")}>Button</Button>
I hope this resolves the issue.
from nextui.
onPress in not available for web it is generally used in react native.
We have to use onKeyDown and then check for Enter Key event
from nextui.
@wingkwong this is generally occuring in every component do you want me to change it for every component. or how do you want me to proceed.
from nextui.
@Inbestigator onClick
has been deprecated. Please use onPress
instead. You can refer to this example. It works with keyboard and it is using onPress.
@abhisektomar1 Your statement is not correct. We do support onPress and other press events.
For those who wonder why onPress
is preferred than onClick
, please check out this blog. "standard" HTML specifications are actually broken across platforms as Mobile devices.
from nextui.
Related Issues (20)
- [BUG] - Getting Frame Drop while Graphics Acceleration turned off HOT 1
- [BUG] - Navbar menu does not scroll in iOS Safari or Chrome HOT 3
- [BUG] - Table HOT 6
- [BUG] - Dropdown HOT 3
- [BUG] - It should display colors in VSCode just like Tailwind CSS variables do HOT 1
- [BUG] - components don't work with `use server` directive HOT 3
- [BUG] - Unintended Movement and Dark Blue Color Issue with NextUI Elements on Mobile Browsers HOT 1
- [BUG] - Datepicker don't apply DateInput classNames HOT 2
- [BUG] add shouldCloseOnInteractOutside to useModal HOT 1
- [BUG] - DatePicker Locale Not Applying en-US Format HOT 2
- [Feature Request] Make a Distinction Between Loading and Error States in Image Component HOT 1
- [BUG] - Lack of RTL Support in Calendar HOT 1
- [BUG] - Lack of RTL Support in Date Range Picker HOT 1
- [BUG] - `React.Key` is not the same as `Key` from `@react-types/shared` HOT 2
- [BUG] - Incompatibility with Next.js 15 HOT 1
- [Feature Request] Ability to provide custom/wrapped TableRow components to a table (and allow other child-bearing list components to be given custom wrappers) HOT 1
- [BUG] - Date picker with month and year HOT 2
- [BUG] - <Input /> clearButton is in the wrong position in Safari HOT 2
- [Feature Request] ListboxItem to support Link state from react-router-dom HOT 1
- [BUG] - Modal does not adjust position when keyboard appears on iOS HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nextui.