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

WIP: refactor: useRovingTabindex to utilize IDs #4292

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

WofWca
Copy link
Collaborator

@WofWca WofWca commented Oct 30, 2024

This should allow us to more easily setActiveElement by its
ID, without having a reference to HTMLElement,
e.g. we can more easily set the initial chat list item.
This issue was mentioned in #4224:

The initially "active" element is just the first chat item,
and not the currently selected chat.

TODO:

  • Rebase and adjust all the references of useRovingTabindex.
  • Test
  • Clean up comments
  • Think whether we actually want to get rid of passing ref to useRovingTabindex. I mean, it's too "raw" and not React-like.
    But perhaps the entire approach is this way, so maybe this is fine.

@WofWca WofWca force-pushed the wofwca/roving-tabindex-refactor-with-ids branch from 997add8 to cb61499 Compare October 30, 2024 10:52
WofWca added a commit that referenced this pull request Oct 30, 2024
Closes #2141

Basically what this commit comes down to:
1. Apply `useRovingTabindex` for message items
2. Set `tabindex="-1"` on all the interactive items
    inside every message that is currently not the active one,
    so that they do no have tab stops.

TODO:
- [ ] Address the TODOs in the code
- [ ] Manage what's gonna be the initially active message,
    because initially they're all active, so
    tabbing to the messages list from the top selects
    the first rendered one as the active one.
    #4292
    could help with this.
    This is also not great for performance: changing `tabindex`
    on a bunch of messages makes them all re-render.
    And otherwise, we probably want to update which one is
    the active one as new messages arrive.
WofWca added a commit that referenced this pull request Oct 30, 2024
Closes #2141

Basically what this commit comes down to:
1. Apply `useRovingTabindex` for message items
2. Set `tabindex="-1"` on all the interactive items
    inside every message that is currently not the active one,
    so that they do no have tab stops.

TODO:
- [ ] Address the TODOs in the code
- [ ] Manage what's gonna be the initially active message,
    because initially they're all active, so
    tabbing to the messages list from the top selects
    the first rendered one as the active one.
    #4292
    could help with this.
    This is also not great for performance: changing `tabindex`
    on a bunch of messages makes them all re-render.
    And otherwise, we probably want to update which one is
    the active one as new messages arrive.
- [ ] The interactive items with `onClick` must be actual semantic
    `<button>`s.
    See #4210
    for reference.
WofWca added a commit that referenced this pull request Oct 30, 2024
Closes #2141

Basically what this commit comes down to:
1. Apply `useRovingTabindex` for message items
2. Set `tabindex="-1"` on all the interactive items
    inside every message that is currently not the active one,
    so that they do no have tab stops.

TODO:
- [ ] Address the TODOs in the code
- [ ] Manage what's gonna be the initially active message,
    because initially they're all active, so
    tabbing to the messages list from the top selects
    the first rendered one as the active one.
    #4292
    could help with this.
    This is also not great for performance: changing `tabindex`
    on a bunch of messages makes them all re-render.
    And otherwise, we probably want to update which one is
    the active one as new messages arrive.
- [ ] The interactive items with `onClick` must be actual semantic
    `<button>`s.
    See #4210
    for reference.
@WofWca WofWca force-pushed the wofwca/roving-tabindex-refactor-with-ids branch from cb61499 to 191b472 Compare November 22, 2024 11:17
packages/frontend/src/contexts/RovingTabindex.tsx Outdated Show resolved Hide resolved
const tabIndex: 0 | -1 =
// If the active element has not been chosen yet,
// let' keep the default behavior (tabindex="0")
context.activeElement == null ||
context.activeElement === elementRef.current
context.activeElementId == null || context.activeElementId === elementId
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

=== null

@WofWca WofWca force-pushed the wofwca/roving-tabindex-refactor-with-ids branch from 191b472 to f9c8af2 Compare December 1, 2024 14:18
This should allow us to more easily `setActiveElement` by its
ID, without having a reference to `HTMLElement`,
e.g. we can more easily set the initial chat list item.
This issue was mentioned in #4224:
> The initially "active" element is just the first chat item,
> and not the currently selected chat.
@WofWca WofWca force-pushed the wofwca/roving-tabindex-refactor-with-ids branch from f9c8af2 to 854003d Compare December 1, 2024 15:18
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.

1 participant