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

feat: make Toggle support keyboard #417

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

peterpeterparker
Copy link
Member

@peterpeterparker peterpeterparker commented Apr 29, 2024

Motivation

I noticed that Toggle couldn't be checked per keyboard navigation. This extend their accessibility for keyboard support.

Changes

  • Add keydown support and accessibility to Toggle component
  • Set width: fit-content given that the toggle can receive focus - i.e. scope active outline style to the element

src/tests/lib/components/Toggle.spec.ts Show resolved Hide resolved
return;
}

input?.click();
Copy link
Collaborator

@dskloetd dskloetd Apr 29, 2024

Choose a reason for hiding this comment

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

For a normal checkbox, one would be able to tab to it to focus it and press space to toggle it, right?
Why is that not possible here, given that the Toggle component is implemented with a checkbox?
Is it because the checkbox has display: none?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it because the checkbox has display: none?

Yes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could it be solved by making the checkbox visibility: hidden and/or height: 0 instead, or by giving it tabindex="0"?

I think it would be preferable if we could rely on the default browser behavior instead of implementing a keydown listener.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure it is a better solution. If we do so, assuming it would work out, then we would need extra CSS and maybe even a state too to highlight correctly focus, hover and other feedback of the related UI components. One or the other...

Copy link
Member Author

Choose a reason for hiding this comment

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

Also probably more development effort.

Copy link
Member Author

@peterpeterparker peterpeterparker Apr 29, 2024

Choose a reason for hiding this comment

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

That said, here I just realized disabled is not handled and should been added to handle the keyboard event in such case.

Let me know if you rather like going CSS etc. and we close the PR (and comeback to this when we've got time) or otherwise I also add a if to handle disable state and improve this PR.

I'm fine either way, your call.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Either way is fine with me.

src/lib/components/Toggle.svelte Show resolved Hide resolved
src/lib/components/Toggle.svelte Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants