Skip to content
Closed
Changes from all 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
5 changes: 5 additions & 0 deletions packages/react/src/Button/ButtonBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ const ButtonBase = forwardRef(({children, as: Component = 'button', ...props}, f
const ariaDescribedByIds = loading ? [loadingAnnouncementID, ariaDescribedBy] : [ariaDescribedBy]

// Check if button contains a keyboard shortcut hint and add data attribute for styling
// TODO: This useLayoutEffect detects [data-kbd-chord] descendants to set data-has-kbd.
// This is a workaround because trailingVisual is opaque and we can't know at render time
// if it contains a KeybindingHint. Ideally, we'd have an explicit prop (e.g., hasKeybindingHint)
// that consumers set, eliminating the need for this runtime DOM query.
// See: https://github.com/primer/react/pull/7402
React.useLayoutEffect(() => {
if (innerRef.current) {
const hasKbd = innerRef.current.querySelector('[data-kbd-chord]') !== null
Expand Down