Skip to content
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

Allow href and onClick in ListGroupItem #1933

Merged
merged 3 commits into from
Aug 19, 2019

Conversation

joshdover
Copy link
Contributor

@joshdover joshdover commented May 8, 2019

Summary

Having an href and an onClick handler is a perfectly valid usecase that EUI should support. There are instances where you may want to override the default behavior with event.preventDefault() in an onClick handler in some conditions, but allow the default behavior in others.

Checklist

  • Documentation examples were added
  • A changelog entry exists and is marked appropriately
  • This was checked for breaking changes and labeled appropriately
  • Jest tests were updated or added to match the most common scenarios

@joshdover joshdover force-pushed the list-group-item-onclick branch from d53abb4 to 5cf9ddd Compare May 8, 2019 19:02
@joshdover joshdover marked this pull request as ready for review May 8, 2019 19:05
@joshdover joshdover requested a review from chandlerprall May 8, 2019 19:05
@chandlerprall chandlerprall requested a review from cchaos May 9, 2019 14:59
@cchaos
Copy link
Contributor

cchaos commented May 9, 2019

@joshdover As you might know this has been quite the controversial topic between EUI and Kibana. However, we've usually resolved that the use-case doesn't or shouldn't actually need this ability. Browser handling of href vs onClick can be unstable, though it is getting better.

Our main concern usually comes back to accessibility. <button>s should behave as buttons (micro-interactions) and <a>s should behave as links (change the page url). Usually if you're forcing the need to do both, it means you're bypassing the natural browser history and routing.

If it's conditional routing/handling of the click that you need, then you should be able to perform that condition before rendering the item and therefore supplying the correct onClick or href.

However, we also don't know your particular use case, so feel free to explain.


Here's a good button vs link checklist that I eventually intend to add to our guidelines:

  • If a screen reader user tabbed onto an interactive element, would its role tell them what to expect? (Would it navigate away from the page? They'd want to know.)
  • Suppressing link features like URL changes or right click? Consider a button.
  • Encourage routing in your application with href, react-router, etc.
  • Page navigation deserves title changes and history.

@joshdover
Copy link
Contributor Author

Got it, thanks for the explanation. I think I've found a way to work around this.

@joshdover joshdover closed this May 10, 2019
@joshdover
Copy link
Contributor Author

joshdover commented Aug 7, 2019

@cchaos I'm reopening this for discussion.

One of the suggestions above is "Encourage routing in your application with href, react-router, etc". The way react-router actually handles this is by using both an href and an onClick handler that calls event.preventDefault in some cases.

This allows both "Open in new tab" behavior via right-click menu or CMD+click as well as allowing the SPA-style navigation history.push calls.

I cannot find a way to replicate this behavior without having both href and an onClick handler. Do you have any suggestions?

@snide
Copy link
Contributor

snide commented Aug 9, 2019

@joshdover Ultimately I think we're throwing our hands up trying to enforce this. To get this PR good to go, can you document some best practices. Specifically just something in the prop docs to say we should attempt not to use onclick and href together. We just need something defensible when we do see this being used over aggressively.

@joshdover joshdover force-pushed the list-group-item-onclick branch 2 times, most recently from 08fb02c to 25cb856 Compare August 9, 2019 16:14
@joshdover
Copy link
Contributor Author

@cchaos this is ready for review.

I also converted this to TypeScript while I was here. This was to help with making sure the comments I added show up in IntelliSense in VSCode. I haven't done this conversion in EUI before, so let me know if there's any steps I missed.

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I'd like @thompsongl to double-check the TS conversions. The docs still behave the same way. Just found a couple typos

CHANGELOG.md Outdated Show resolved Hide resolved
src/components/list_group/list_group_item.tsx Outdated Show resolved Hide resolved
@cchaos cchaos requested a review from thompsongl August 13, 2019 18:04
@joshdover joshdover force-pushed the list-group-item-onclick branch from 25cb856 to c78a24c Compare August 13, 2019 20:13
@joshdover joshdover removed the request for review from chandlerprall August 13, 2019 20:14
Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TS conversion looks good to me

@thompsongl
Copy link
Contributor

@joshdover I think this is good to go once the conflict is resolved

@joshdover joshdover force-pushed the list-group-item-onclick branch from c78a24c to fb93a3b Compare August 19, 2019 15:00
@thompsongl thompsongl merged commit b5dc774 into elastic:master Aug 19, 2019
@joshdover joshdover deleted the list-group-item-onclick branch August 19, 2019 16:03
thompsongl pushed a commit to thompsongl/eui that referenced this pull request Sep 10, 2019
* Allow href and onClick in ListGroupItem

* Convert EuiListGroup to TypeScript

* PR comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants