-
Notifications
You must be signed in to change notification settings - Fork 14
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
Use SelectNext for StudentSelector #5764
Conversation
4a5e723
to
44d7937
Compare
lms/static/scripts/frontend_apps/components/StudentSelector.tsx
Outdated
Show resolved
Hide resolved
5f4bffb
to
1211885
Compare
This is probably because of the label I added to mimic the previous I suppose screen readers read both label and select, but when the label is linked to a button, it "replaces" the button instead of adding. What I don't know is why it announces the first part, "Student 1 of 2". That is not linked with the select as far as I can tell 🤔 I'll check it just in case.
We discussed this for the comment popover, but that one is closed only with In the case of I guess that, if the focus has moved to a different frame, the events don't trigger as one would expect. I will try to put together a sandbox to test this. |
That issue ☝🏼 should be addressed by this PR hypothesis/frontend-shared#1326 |
@robertknight I have found out why it now announces "Student 1 of 2". The reason is that it is a Apparently, the previous My suggestion is that we remove the diff --git a/lms/static/scripts/frontend_apps/components/StudentSelector.tsx b/lms/static/scripts/frontend_apps/components/StudentSelector.tsx
index aa9469c0..d1d9e8bb 100644
--- a/lms/static/scripts/frontend_apps/components/StudentSelector.tsx
+++ b/lms/static/scripts/frontend_apps/components/StudentSelector.tsx
@@ -52,7 +52,6 @@ export default function StudentSelector<Student extends StudentOption>({
<label
className="font-semibold text-xs"
data-testid="student-selector-label"
- htmlFor={selectId}
>
{hasSelectedStudent ? (
<>
@@ -78,7 +77,7 @@ export default function StudentSelector<Student extends StudentOption>({
variant="dark"
/>
<label className="sr-only" htmlFor={selectId}>
- Select student
+ {selectedStudent?.displayName} Select student
</label>
<SelectNext
classes="md:!w-[12rem] lg:!w-[16rem] xl:!w-[20rem]" The only drawback is that clicking in the "Student 1 of 2" label will no longer focus the select, but considering how "small" it is, I think it's negligible. What do you think? |
1211885
to
947168f
Compare
Hi @acelaya, I should have been clearer. The inclusion of "Student 1 of 2" in the new caption is not the problematic change here. In fact I think it is fine to leave that as-is. Removing the |
Gotcha. Then I think just adding the name of the student in the new label should be enough: diff --git a/lms/static/scripts/frontend_apps/components/StudentSelector.tsx b/lms/static/scripts/frontend_apps/components/StudentSelector.tsx
index aa9469c0..47cc4eca 100644
--- a/lms/static/scripts/frontend_apps/components/StudentSelector.tsx
+++ b/lms/static/scripts/frontend_apps/components/StudentSelector.tsx
@@ -78,7 +78,7 @@ export default function StudentSelector<Student extends StudentOption>({
variant="dark"
/>
<label className="sr-only" htmlFor={selectId}>
- Select student
+ {selectedStudent?.displayName} Select student
</label>
<SelectNext
classes="md:!w-[12rem] lg:!w-[16rem] xl:!w-[20rem]" With that it announces mostly the same as before, but prefixed with "Student 1 of 2" or whatever the uppermost label says. |
c12dca4
to
bbb1aff
Compare
@robertknight I have pushed the fixes mentioned in previous comments and updated to frontend-shared v6.9.0, which includes some extra fixes needed for the LMS |
Explicitly adding the control value into the label is something that Aside from not wanting to make each use of
The screen reader then reads these out in order, eg. as Taking the grade input as an example, the properties can be inspected in the Accessibility panel of the Elements tab: I wondered how other libraries we've been looking at handle this. The React Spectrum picker uses two I couldn't easily see how Headless UI's example works because their reference page doesn't have an example with a label. The example at https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ on the other hand uses the combobox pattern. That ARIA role allows for a separation between value and label, and is read out correctly by in all 3 browsers. This allows a native I had a look at Chrome's implementation of the Turning our control into a combobox by adding In summary:
|
Thanks Rob. Super detailed explanation and investigation. Putting this in draft again, while I try to refactor |
bbb1aff
to
de6b7ef
Compare
I have tested this branch with the changes from hypothesis/frontend-shared#1330, and it solves the issues with screen readers. |
de6b7ef
to
8eb49d9
Compare
I have updated to frontend-shared 6.9.1, which includes the refactored SelectNext with combobox role. This PR is ready for review again. |
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.
LGTM. The updated SelectNext
now works as expected.
lms/static/scripts/frontend_apps/components/StudentSelector.tsx
Outdated
Show resolved
Hide resolved
lms/static/scripts/frontend_apps/components/StudentSelector.tsx
Outdated
Show resolved
Hide resolved
aria-label="Select student" | ||
classes="xl:w-80" | ||
id="student-selector" | ||
<label |
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.
Now that we actually have this UI implemented, I'm not sure there is value in keeping the toolbar page, which is going to get out of sync with the actual implementation. We could decide to remove these prototypes. We'll always have the code in Git if we need to get them back.
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.
Sounds reasonable.
8eb49d9
to
72ad6f3
Compare
This PR replaces
Select
withSelectNext
in theStudentSelector
.Before:
After:
SelectNext
needs to have a "fixed" size to make sure it does not resize when selected option changes, so I have changed its sizes to be:Grabacion.de.pantalla.desde.2023-10-18.11-56-35.webm
Testing steps
Open any assignment and verify students can be selected as with the regular select.