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

Simplify events #73

Merged
merged 4 commits into from
Feb 16, 2024
Merged

Simplify events #73

merged 4 commits into from
Feb 16, 2024

Conversation

keithamus
Copy link
Member

This simplifies some of the logic around event handlers; prior to this change the event handlers were arrow functions inside addEventListener inside the connectedCallback, which made it harder to see what was happening in connectedCallback. This PR moves them out into their own private functions, instead.

It also simplifies the logic for the functions; they were doing a lot of unnecessary checks, and handleKeydown had some logic spread around the codebase in a function declaration. This now moves the logic inline so that the functions read completely, without having to jump around the codebase.

@keithamus keithamus requested a review from a team as a code owner February 16, 2024 11:46
Copy link
Member

@owenniblock owenniblock left a comment

Choose a reason for hiding this comment

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

Nice!


const currentIndex = tabs.indexOf(tabs.find(e => e.matches('[aria-selected="true"]'))!)
const vertical = tab.closest('[role="tablist"]')?.getAttribute('aria-orientation') === 'vertical'
const prevTab = event.code === 'ArrowLeft' || (vertical && event.code === 'ArrowUp')
Copy link
Member

Choose a reason for hiding this comment

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

Reminder for myself to check that we're setting the aria-orientation when we set horizontal or vertical.

@keithamus keithamus merged commit 9993b1d into main Feb 16, 2024
2 checks passed
@keithamus keithamus deleted the simplify-events branch February 16, 2024 12: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.

2 participants