question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add onDisabledClick handler

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

When some UI elements are disabled, users may struggle to figure out why. Examples include a submit form button that cannot be pressed, a menu item that’s greyed out etc. As a user, I still sometime press on these elements even though they are pale, but only rarely get any useful feedback.

In the best case scenario, clicking a greyed-out Submit button in a form scrolls me to a field that I have made a mistake in and switches the cursor to the right input element. For a disabled menu item, a well-made UI would show me a notification message or give some hint about the current situation somehow else.

It’d be great if ant design had something like onDisabledClick prop in various components. In my opinion, this can significantly improve the UX in cases when it’s critical to guide users towards the system goal. Because onDisabledClick will have an arbitrary logic, it can be accompanied with another a11y prop for screen reader users. I’m not sure about the name of that prop, but it can just contain a string message that would work as a hint.

What does the proposed API look like?

<Button disabled={trueOrFalse} onClick={executeAction} onDisabledClick={() => message.info('You cannot do this action at the moment because of XYZ');} />
<Menu onClick={handleMenuItemClick} onDisabledClick={({ key }) => notification.open({ message: `You cannot use ${key} because ${reasons[key]}`});}>
  <Menu.Item key="action1">Action 1</Menu.Item>
  <Menu.Item key="action2" disabled={true}>Action 2</Menu.Item>
</Menu>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ztplzcommented, Feb 9, 2019

You can use div wrap the disabled button, see this demo. This will allow you to prompt the user and count user clicks.

0reactions
kachkaevcommented, Feb 8, 2019

Thanks for the suggestion! I’ll give it a try and report back if the result is successful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to replace event handler when button is disabled
When you re-enable the button, remove the disabled onclick event handler, and add the normal event handler back. You can do this with...
Read more >
Solved:Is there a way to disable click on an element with an ...
I have a bunch of flags and if's but it seems an ugly solution. Removing and adding the event listeners is also ugly....
Read more >
Seccl UI Patterns
Icons can be added to a button to either the left or right of the text. ... Clicking on a disabled button will...
Read more >
Tips On How To Add And Manage Shopify Product Reviews
Find the "Auto Publish" option and click on "disabled". Click "Save" to save your current setting. Turning the "Auto Publish" feature means that ......
Read more >
Accessible JavaScript Click Handlers | Keeping Up To Date
One way to drastically exclude users from your site is to add JavaScript click handlers to non-interactive elements such as ` ` and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found