WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Accessibility improvements: focus trapping, keyboard navigation, and controlling auto-close behavior #1211

@stevelacey

Description

@stevelacey

Hi, first of all thank you for the work on this package. The documentation mentions accessibility as an ongoing consideration, but I have found it fairly difficult to get some common accessibility patterns working in practice. I figured I would share the problems I have run into in case they help guide future improvements.

1. Focus trapping is hard to implement externally

I try to wrap all dropdown and popup components in a focus trap for accessibility. With this datepicker it has been quite tricky.

It is somewhat easier to manage when teleport: false, although there are still edge cases. Once teleport: true is used it becomes very difficult to attach a reliable focus trap around the menu. I can work around this a bit by querying for the dynamic .dp--menu-wrapper:not(:empty) element, but it is brittle.

It might be beyond the scope of the library to include a focus trap by default, but exposing a more stable hook, slot, or mount point would make it much easier.

2. Preventing auto-close is inconsistent

Even with the tab-out options disabled, I still see the picker closing itself in situations that seem hard or impossible to prevent:

  • Shift+Tabing away from the picker always seems to trigger a close.
  • I suspect this is being triggered by internal blur-handling or by focus returning to the input.
  • For context: I am using the dp-input slot with all the recommended bindings. I have not tested without that slot.

This makes it difficult to use a focus trap or manage keyboard navigation inside the menu without fighting the auto-close logic.

3. Custom keyboard handling is difficult to implement

I would like to customise some of the keyboard interactions; for example:

  • Using Space for date selection during keyboard navigation.
  • Making Enter consistently behave as “select and close”.
  • Preventing Enter from bubbling up and submitting the surrounding form.

Right now it is hard to bind these cleanly because:

  • When teleport: false, it is difficult to access the internal elements that need preventDefault or stopPropagation.
  • When teleport: true, some bindings work better but it is still very hard to avoid breaking built-in interactions such as the action buttons.
  • There is no clear way to intercept keydown events at the correct level without interfering with internals.

I am not sure what the ideal solution is. More slots, more event hooks, or more granular disable-options might help. My goal here is mostly to highlight the friction points in case they are useful for planning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting triageThe issue is not reviewed by the maintainersenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions