GithubHelp home page GithubHelp logo

Comments (6)

linear avatar linear commented on August 15, 2024

ENG-1079 [BUG] - <Button> onClick handler is not triggered by keyboard

from nextui.

abhisektomar1 avatar abhisektomar1 commented on August 15, 2024

I am working on it.

from nextui.

awesome-pro avatar awesome-pro commented on August 15, 2024

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

  1. Go to any page with component.
  2. Set focus on (for example, by tabbing).
  3. Press Spacebar or Enter key.
  4. 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.

abhisektomar1 avatar abhisektomar1 commented on August 15, 2024

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.

abhisektomar1 avatar abhisektomar1 commented on August 15, 2024

@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.

wingkwong avatar wingkwong commented on August 15, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.