Skip to content
Closed
Show file tree
Hide file tree
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
11 changes: 3 additions & 8 deletions packages/react/src/Button/ButtonBase.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
justify-content: space-between;
gap: var(--base-size-8);

/* NOTE: Uses descendant :has() - button has very few children (icon, text, kbd). Acceptable. */
&:has([data-kbd-chord]) {
&[data-has-kbd] {
padding-inline-end: var(--base-size-6);
}

Expand Down Expand Up @@ -174,8 +173,7 @@
margin-right: var(--control-large-gap);
}

/* NOTE: Uses descendant :has() - button has very few children (icon, text, kbd). Acceptable. */
&:has([data-kbd-chord]) {
&[data-has-kbd] {
padding-inline-end: var(--base-size-8);
}
}
Expand Down Expand Up @@ -637,11 +635,8 @@

/*
* Icon-only + Counter
* NOTE: Uses descendant :has() - leadingVisual and text are nested inside
* buttonContent wrapper. This is acceptable as the search is scoped to
* this single button element's subtree (small DOM).
*/
&:where([data-has-count]):has([data-component='leadingVisual']):not(:has([data-component='text'])) {
&:where([data-has-count][data-has-leading-visual]:not([data-has-text])) {
/* stylelint-disable-next-line primer/spacing */
padding-inline: var(--control-medium-paddingInline-condensed);

Expand Down
15 changes: 15 additions & 0 deletions packages/react/src/Button/ButtonBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ const ButtonBase = forwardRef(({children, as: Component = 'button', ...props}, f
// Only include the loading aria-describedby if there is a loading state
const ariaDescribedByIds = loading ? [loadingAnnouncementID, ariaDescribedBy] : [ariaDescribedBy]

// Check if button contains a keyboard shortcut hint and add data attribute for styling
React.useLayoutEffect(() => {
if (innerRef.current) {
const hasKbd = innerRef.current.querySelector('[data-kbd-chord]') !== null
if (hasKbd) {
innerRef.current.setAttribute('data-has-kbd', 'true')
} else {
innerRef.current.removeAttribute('data-has-kbd')
}
}
})

if (__DEV__) {
/**
* The Linter yells because it thinks this conditionally calls an effect,
Expand Down Expand Up @@ -99,6 +111,9 @@ const ButtonBase = forwardRef(({children, as: Component = 'button', ...props}, f
data-inactive={inactive ? true : undefined}
data-loading={Boolean(loading)}
data-no-visuals={!LeadingVisual && !TrailingVisual && !TrailingAction ? true : undefined}
data-has-visuals={LeadingVisual || TrailingVisual ? true : undefined}
data-has-leading-visual={LeadingVisual ? true : undefined}
data-has-text={children ? true : undefined}
data-size={size}
data-variant={variant}
data-label-wrap={labelWrap}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`Button > respects block prop 1`] = `
<button
class="prc-Button-ButtonBase-Eb8-K"
data-block="block"
data-has-text="true"
data-loading="false"
data-no-visuals="true"
data-size="medium"
Expand All @@ -29,6 +30,7 @@ exports[`Button > respects block prop 1`] = `
exports[`Button > respects the alignContent prop 1`] = `
<button
class="prc-Button-ButtonBase-Eb8-K"
data-has-text="true"
data-loading="false"
data-no-visuals="true"
data-size="medium"
Expand All @@ -54,6 +56,7 @@ exports[`Button > respects the alignContent prop 1`] = `
exports[`Button > respects the large size prop 1`] = `
<button
class="prc-Button-ButtonBase-Eb8-K"
data-has-text="true"
data-loading="false"
data-no-visuals="true"
data-size="large"
Expand All @@ -79,6 +82,7 @@ exports[`Button > respects the large size prop 1`] = `
exports[`Button > respects the small size prop 1`] = `
<button
class="prc-Button-ButtonBase-Eb8-K"
data-has-text="true"
data-loading="false"
data-no-visuals="true"
data-size="small"
Expand All @@ -104,6 +108,7 @@ exports[`Button > respects the small size prop 1`] = `
exports[`Button > styles danger button appropriately 1`] = `
<button
class="prc-Button-ButtonBase-Eb8-K"
data-has-text="true"
data-loading="false"
data-no-visuals="true"
data-size="medium"
Expand All @@ -129,6 +134,7 @@ exports[`Button > styles danger button appropriately 1`] = `
exports[`Button > styles invisible button appropriately 1`] = `
<button
class="prc-Button-ButtonBase-Eb8-K"
data-has-text="true"
data-loading="false"
data-no-visuals="true"
data-size="medium"
Expand All @@ -154,6 +160,7 @@ exports[`Button > styles invisible button appropriately 1`] = `
exports[`Button > styles primary button appropriately 1`] = `
<button
class="prc-Button-ButtonBase-Eb8-K"
data-has-text="true"
data-loading="false"
data-no-visuals="true"
data-size="medium"
Expand Down
Loading