Skip to content

Send original event details in combobox-commit CustomEvent#66

Merged
colinwm merged 3 commits into
mainfrom
colinwm-combobox-commit
Dec 14, 2022
Merged

Send original event details in combobox-commit CustomEvent#66
colinwm merged 3 commits into
mainfrom
colinwm-combobox-commit

Conversation

@colinwm

@colinwm colinwm commented Dec 12, 2022

Copy link
Copy Markdown
Contributor

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 Dec 12, 2022
@primer-css

Copy link
Copy Markdown

👋 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.

@koddsson koddsson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me!

Comment thread 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
Copy Markdown
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)

Comment thread src/index.ts Outdated

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

@rezrah rezrah Dec 13, 2022

Copy link
Copy Markdown

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.

@rezrah rezrah left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

@colinwm colinwm requested review from koddsson and rezrah December 13, 2022 15:59
@colinwm

colinwm commented Dec 13, 2022

Copy link
Copy Markdown
Contributor Author

@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

4 participants