-
Notifications
You must be signed in to change notification settings - Fork 21
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
fix(header-dropdown): click list item to close #973
Conversation
Playwright test resultsDetails
Skipped testssrc/components/table/table/test/expandable-row-autocollapse/expandable-row-autocollapse.e2e.ts › tds-table-expandable-row-autoCollapse › NEEDS FIXING: expanding one row collapses the others when autoCollapse is true |
This pull request is automatically being deployed by Amplify Hosting (learn more). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, it works as intended by my testing, just wondering if we need a
& button
if we add div
? since div
is the wrapping element? what element are is the source when clicking on the icon or text? should we be more specific, can we check if it is an header-item
?
packages/core/src/components/header/header-dropdown/header-dropdown.tsx
Outdated
Show resolved
Hide resolved
e1aaef6
to
bf72d61
Compare
@Lunkan89 I tested it just now, and having only div causes it to not work when clicking outside of the text or icon |
65ad727
to
555b33a
Compare
@Lunkan89 @theJohnnyMe Thanks for your feedback! I updated the code now, to instead emit an event from header-dropdown-list-item. So now, if a list item (row) is clicked, it closes the dropdown. Not sure if we always want clicks on list items to close the dropdown though... What do you think? |
555b33a
to
8e84437
Compare
In the case that a user successfully slots in another dropdown as a list item it might be problematic if the main dropdown closes when a user clicks on the slotted dropdown in an attempt to open it. We might be shooting ourselves in the foot by harshly specifying that all list items closes the dropdown. |
That's a good point. For that reason perhaps it's better with the solution in the first commit... However, perhaps the element that is clicked to open the inner dropdown would also be a div, if it is then it will close the outer dropdown when trying to open the inner. I'll look into this. Perhaps another solution would be to add a prop to the header-dropdown-list-item component such as closeOnClick which is true by default, but that could be set to false in case one wants to e.g. open an inner dropdown when clicking on the list item. Could this work? |
8e84437
to
97c2696
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do believe this would work, however I'm wondering about the implementation this would require. From what i can understand the user would have to listen to the newly created event 'closeDropdownFromListItem' on all list items in the header dropdown except the one/few that would potentially open something else, have I understood that correctly? If yes, it would mean a lot of repeating event listeners for a lot of list items. Maybe it would be more desirable to have something the user can opt out of instead, like a "don't close dropdown when this list item is clicked" or similar. Or have I completely misunderstood your implementation? 🙃
@nathalielindqvist |
OK, let's go back to the initial issue. The problem is that when the user clicks directly on the icon or text in the anchor tag, the dropdown does not close. I believe the reason is that we have code like this:
Instead of
So when you click on an Icon or a text, you are clicking on it, not on the In the browser I did a small test by setting Another, no so much desired way, would be to try to add As I see the user has not requested control to toggle off or on logic for the closing of dropdown so let's keep that discussion out. |
97c2696
to
a6409eb
Compare
a6409eb
to
5421d64
Compare
826e3f1
to
b09b942
Compare
Demo available here now: https://pr-210.d2vh2lmnzgzrkl.amplifyapp.com/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one! LGTM
b09b942
to
40ed740
Compare
|
Describe pull-request
Adds div to list of event sources that close the header dropdown.Adds an event emitter to header-dropdown-list-item that is handled in header-dropdown, where it closes the dropdown.Adds "pointer-events: none" for relevant inner elements to not interrupt event to close header dropdown. Thank you to @theJohnnyMe for help with the solution :)
Issue Linking:
How to test
Checklist before submission
npm run build-all
without errorsSuggested test steps
Screenshots
None
Additional context
I'm not sure if this is a very good solution, adding div as a source of event that closes the dropdown. But the way the dropdown is currently closed is handled like this (when the click is done inside the header-dropdown). I imagine a better solution would be to somehow specify the user clicks anywhere in a dropdown row, it closes it, without specifying that it should be a div.The reason I added div specifically is because in the ticket for this PR, the problem was mentioned to be in React, and after investigating I found that the element that is clicked is a next Link (which is compiled to a div).