Update IconButton to support multiple keybinding hints#7623
Update IconButton to support multiple keybinding hints#7623
Conversation
🦋 Changeset detectedLatest commit: c1bcdf4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-authored-by: iansan5653 <2294248+iansan5653@users.noreply.github.com>
| const keybindingHints = keybindingHint | ||
| ? Array.isArray(keybindingHint) | ||
| ? keybindingHint | ||
| : [keybindingHint] | ||
| : undefined |
There was a problem hiding this comment.
@copilot this should be undefined if keybindingHint is an empty array so that it doesn't configure extra properties for an empty hint
There was a problem hiding this comment.
Fixed in 6818499. An empty array now resolves to undefined, preventing any keybinding hint rendering or extra configuration.
Co-authored-by: iansan5653 <2294248+iansan5653@users.noreply.github.com>
Co-authored-by: iansan5653 <2294248+iansan5653@users.noreply.github.com>
|
There was a problem hiding this comment.
Pull request overview
Extends IconButton/TooltipV2 keybinding hint support to allow multiple shortcut hints, rendering them as multiple KeybindingHint elements separated by " or ", and updating the accessible label accordingly.
Changes:
- Widened
keybindingHinttypes to acceptstring | string[](and passed throughTooltipV2). - Updated
TooltipV2rendering + accessible label generation to handle multiple hints with" or "separators, treating[]as no hint. - Added Storybook coverage and unit tests for the multiple-hints behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/TooltipV2/Tooltip.tsx | Normalizes keybindingHint into a list, updates visible and VisuallyHidden rendering to support multiple hints. |
| packages/react/src/TooltipV2/tests/Tooltip.test.tsx | Adds tests for multi-hint accessible name, rendering, and empty-array behavior. |
| packages/react/src/Button/types.ts | Updates IconButtonProps.keybindingHint type to `string |
| packages/react/src/Button/IconButton.features.stories.tsx | Adds a Storybook feature story demonstrating multiple keybinding hints. |
| .changeset/iconbutton-keybinding-hint-array.md | Declares a minor release for the new IconButton.keybindingHint array support. |
|
👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/15156 |
iansan5653
left a comment
There was a problem hiding this comment.
@copilot when there multiple keybinding hints, we need more space between the main label text and the hints or it gets too crowded and confusing
add some more space, but only when there's more than one hint to show
| const hasAriaLabel = 'aria-label' in rest | ||
|
|
||
| // Normalize keybindingHint to an array for uniform rendering, treating empty arrays as undefined | ||
| const keybindingHints = keybindingHint |
There was a problem hiding this comment.
I actually think it would be simpler to allow empty arrays and just check for keybindingHint.length in the later conditionals
There was a problem hiding this comment.
Done in d0bf446. keybindingHints now normalizes to [] for falsy/empty-array inputs, and the later conditionals use .length === 0 / .length > 0 checks.
|
Integration test results from github/github-ui:
CI check runs linting, type checking, and unit tests. Check the workflow logs for specific failures. Need help? If you believe this failure is unrelated to your changes, please reach out to the Primer team for assistance. |
…iple hints Co-authored-by: iansan5653 <2294248+iansan5653@users.noreply.github.com>
Added in d0bf446. A |
| tooltipDirection?: TooltipDirection | ||
| /** @deprecated Use `keybindingHint` instead. */ | ||
| keyshortcuts?: string | ||
| keybindingHint?: string |
There was a problem hiding this comment.
correct type in iconbutton.docs.json as well
There was a problem hiding this comment.
Done in 464c69d. Updated keybindingHint type in IconButton.docs.json from "string" to "string | string[]" and updated the description to mention the array form.
| text: string | ||
| type?: 'label' | 'description' | ||
| keybindingHint?: KeybindingHintProps['keys'] | ||
| keybindingHint?: KeybindingHintProps['keys'] | Array<KeybindingHintProps['keys']> |
There was a problem hiding this comment.
correct type on tooltip.docs.json as well
There was a problem hiding this comment.
Done in 464c69d. Updated keybindingHint type in Tooltip.docs.json from "string" to "string | string[]" and updated the description accordingly.
| // Normalize keybindingHint to an array for uniform rendering | ||
| const keybindingHints = keybindingHint ? (Array.isArray(keybindingHint) ? keybindingHint : [keybindingHint]) : [] |
There was a problem hiding this comment.
is it possible to default keyBindingHint to empty array to simplify this and make it more readable?
There was a problem hiding this comment.
Done in 464c69d. keybindingHint now defaults to [] in the destructuring, so the normalization simplifies to just Array.isArray(keybindingHint) ? keybindingHint : [keybindingHint].
There was a problem hiding this comment.
@copilot extract the empty array default out to a constant, like:
const emptyArray = []
function Tooltip({keybindingHint = emptyArray}) {...}There was a problem hiding this comment.
Done in c1bcdf4. Added const emptyKeybindingHints: Array<KeybindingHintProps['keys']> = [] at module level and updated the default to reference it.
|
@copilot implement requested changes |
…ion with default prop Co-authored-by: francinelucca <40550942+francinelucca@users.noreply.github.com>
|
nice, thanks for catching that! I always forget that the docs aren't powered by TypeScript types |
…ble reference Co-authored-by: iansan5653 <2294248+iansan5653@users.noreply.github.com>
Extends
IconButton'skeybindingHintprop to accept an array of strings in addition to a single string. Multiple keybinding hints are rendered joined with "or" (e.g.,["Mod+B", "Control+B"]renders as⌘B or ⌃B). An empty array is treated the same as omitting the prop entirely.Changelog
New
IconButton.keybindingHintnow acceptsstring | string[]. When an array is provided, each hint is rendered as aKeybindingHintcomponent with " or " separators between them."Bold (command b or control b)").Changed
TooltipProps.keybindingHintwidened fromstringtostring | string[]to support the array form (IconButton passes this value through to Tooltip).keybindingHintproduces no hint rendering —keybindingHintdefaults to a stable module-levelemptyKeybindingHintsconstant in Tooltip's prop destructuring, and.lengthchecks are used in conditionals throughout.var(--base-size-8)vsvar(--base-size-6)) is applied between the label text and the hint badges to avoid crowding.keybindingHinttype corrected tostring | string[]in bothTooltip.docs.jsonandIconButton.docs.json.Removed
Rollout strategy
Testing & Reviewing
New Storybook story:
Components/IconButton/Features — MultipleKeybindingHintsdemonstrates the array form.New unit tests cover:
KeybindingHintelements are rendered with a " or " separatorMerge checklist
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.