-
Notifications
You must be signed in to change notification settings - Fork 6
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
DSD-1740/close dropdown multiselect #1607
DSD-1740/close dropdown multiselect #1607
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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 think your tests may break based on my comment so will review that once this is updated.
@@ -14,7 +14,18 @@ export const changelogData: ChangelogData[] = [ | |||
version: "Prerelease", | |||
type: "Update", | |||
affects: ["Accessibility", "Functionality"], | |||
notes: ["Adds logic to close accordion when 'esc' key is pressed"], | |||
notes: [ | |||
"Adds logic to close accordion when element within panel is focused and 'esc' key is pressed", |
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.
This is duplicated below.
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.
They're slightly different, but I can combine them if you prefer.
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.
You can keep both but what I mean is you only need one object with "Prerelease" but now there are two. Unless if this was done because you don't think this will get deployed by 5/23. If that's the case then it's okay to keep both.
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 see! Okay. Will combine.
setExpandedPanels( | ||
expandedPanels.filter((i) => i !== focusedPanelIndex) | ||
); |
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.
This is within the else
block and it doesn't seem intentional because the esc key should still be functional when the user is focused on the accordion button.
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.
Yes! Good catch. Thank you.
} else { | ||
// If the user is focused on an element within the panel... | ||
focusedPanelIndex = Number( | ||
e.target.closest("[role='region']").id.split("-").pop() |
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, but also brittle if the DOM and/or id ever changes.
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 know :/, I didn't want to do it this way, but it seemed like the best option...the id is really the only way the panel is connected to the button that needs to close.
@@ -160,19 +160,17 @@ describe("Accordion", () => { | |||
}); | |||
|
|||
it("closes the accordion when the 'esc' key is pressed", async () => { | |||
render(<Accordion accordionData={[accordionData[0]]} isDefaultOpen />); | |||
render(<Accordion accordionData={[accordionData[0]]} />); |
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.
Can you add another test where the entire accordionData
array is passed, so now there are three accordions. For one of the accordions, add a button or checkbox, focus on it, and then press escape. This is to test the new feature in this PR but also that it works when there are more than just one accordion.
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 know there's a test that does this for MultiSelect
but the feature is in the Accordion so it should also be tested there.
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.
Done!
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.
Please see my comment about how focus should be handled.
@@ -4,7 +4,7 @@ import { | |||
ChakraComponent, | |||
useMultiStyleConfig, | |||
} from "@chakra-ui/react"; | |||
import React, { useState, forwardRef, useRef } from "react"; | |||
import React, { forwardRef, useRef, useState } from "react"; |
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 was not sure where to put this comment, but the focus needs to be addressed after the ESC key is pressed when a checkbox has focus. In that scenario, the focus should return to the main button after the ESC key is pressed.
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.
That's a good point. If it involves having state or ref we should talk about this because it's getting overly complex and from what I understood, accordions don't generally behave this way. So if we don't have to implement this then perhaps we should not.
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.
We don't need it for Accordion
, but we do need it for MultiSelect
.
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.
That's true but the Accordion
is a big part of the MultiSelect
and, to me, MultiSelect
is inheriting all the features of Accordion
. There is currently a ref that is being passed from the MultiSelect
to the Accordion
to keep track of focus for when the items count button is clicked. This could be used as well when the esc key is pressed. But it we have to keep track of pressing the ESC key in the MultiSelect to close the Accordion, then it feels like the work is being duplicated because the Accordion
already does check for when the ESC key is pressed.
Perhaps we should reconsider and move all the logic just to the MultiSelect
from the Accordion
. @oliviawongnyc As you try to implement the focus management in the Accordion
, let me know if my comment makes sense.
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.
Okay @EdwinGuzman and @bigfishdesign13, focus should now return to the button when the Accordion
(or MultiSelect
) is closed with the esc
key.
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.
Update looks good but tests are failing
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.
The esc
focus handling works great in MultiSelect
, but it is not working in Accordion
.
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.
The update looks good to me and it works in both the Accordion
and MultiSelect
.
// user is focused on or within, and remove it as | ||
// an expanded panel. (Nothing will happen if the | ||
// panel is already collapsed.) | ||
if (e.code === "Escape") { |
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.
Just curious, why the update from e.keyCode
to e.code
?
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.
Two reasons. 1) I thought it was clearer than. using a keyCode, and 2) for some reason in the tests, the keyCode for Escape was a different number than it is in the code? So I used the code 'Escape' instead for the tests and wanted to be consistent.
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.
Really nice refactor in the last commit.
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.
Awesome!
Fixes JIRA ticket DSD-1740
This PR does the following:
esc
).How has this been tested?
Accessibility concerns or updates
Checklist:
Front End Review: