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

Conversation

colinwm
Copy link
Member

@colinwm colinwm commented Dec 12, 2022

I want to get some additional information about the originating trigger of the commit event (whether the ctrlKey or metaKey are pressed) to determine whether links should be opened in a new tab or not. Seems that information is not preserved in the combobox-commit CustomEvent.

I plumbed it through via details, lmk if you think this is reasonable

@colinwm colinwm requested a review from a team as a code owner December 12, 2022 21:39
@colinwm colinwm changed the title Send original triggering event details in combobox-commit CustomEvent Send original event details in combobox-commit CustomEvent Dec 12, 2022
@primer-css
Copy link

👋 Hello and thanks for pinging us! This issue or PR has been added to our inbox and a Design Infrastructure first responder will review it soon.

  • 🎨 If this is a PR that includes a visual change, please make sure to add screenshots in the description or deploy this code to a lab machine with instructions for how to test.
  • If this is a PR that includes changes to an interaction, please include a video recording in the description.
  • ⚠️ If this is urgent, please visit us in #primer on Slack and tag the first responders listed in the channel topic.

Copy link
Contributor

@koddsson koddsson left a comment

Choose a reason for hiding this comment

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

Looks good to me!

src/index.ts Outdated
Comment on lines 187 to 188
function fireCommitEvent(target: Element, originalEvent?: MouseEvent): void {
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)

src/index.ts Outdated
@@ -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.

Copy link

@rezrah rezrah left a comment

Choose a reason for hiding this comment

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

👍

@colinwm
Copy link
Member Author

colinwm commented Dec 13, 2022

@koddsson @rezrah PTAL, I updated to use your detail suggestion

@colinwm colinwm merged commit 155261e into main Dec 14, 2022
@colinwm colinwm deleted the colinwm-combobox-commit branch December 14, 2022 16:33
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.

4 participants