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

Send original event details in combobox-commit CustomEvent #66

Merged
merged 3 commits into from
Dec 14, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function commitWithElement(event: MouseEvent) {
const target = event.target.closest('[role="option"]')
if (!target) return
if (target.getAttribute('aria-disabled') === 'true') return
fireCommitEvent(target)
fireCommitEvent(target, event)
}

function commit(input: HTMLTextAreaElement | HTMLInputElement, list: HTMLElement): boolean {
Expand All @@ -184,8 +184,8 @@ function commit(input: HTMLTextAreaElement | HTMLInputElement, list: HTMLElement
return true
}

function fireCommitEvent(target: Element): void {
target.dispatchEvent(new CustomEvent('combobox-commit', {bubbles: true}))
function fireCommitEvent(target: Element, originalEvent?: MouseEvent): void {
Copy link

@rezrah rezrah Dec 13, 2022

Choose a reason for hiding this comment

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

Nit. For simplicity and consistency with the other arguments in this file, I think this could just be event as there's no superseding assignment or event mutation inside the closure. When I see original*, I usually expect something to happen to it after but it's just being forwarded here.

target.dispatchEvent(new CustomEvent('combobox-commit', {bubbles: true, detail: {originalEvent}}))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick; What do you think about taking in details as a argument so that we adhere more to the API of CustomEvent?

Suggested change
function fireCommitEvent(target: Element, originalEvent?: MouseEvent): void {
target.dispatchEvent(new CustomEvent('combobox-commit', {bubbles: true, detail: {originalEvent}}))
function fireCommitEvent(target: Element, detail: Record<string, unknown> | undefined = undefined): void {
target.dispatchEvent(new CustomEvent('combobox-commit', {bubbles: true, detail}))

(☝🏻 I wrote this suggestion in the GitHub comment box so it might be wrong)

}

function visible(el: HTMLElement): boolean {
Expand Down