Skip to content

Commit c7c1ec8

Browse files
committed
updates Button 'link' variant to respect user's underline preference
1 parent 12fad7a commit c7c1ec8

4 files changed

Lines changed: 66 additions & 2 deletions

File tree

e2e/components/Button.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ const stories = [
8787
title: 'Trailing Counter No Text',
8888
id: 'components-button-features--trailing-counter-with-no-text',
8989
},
90+
{
91+
title: 'Dev Link Variant With Underline Preference',
92+
id: 'components-button-dev--link-variant-with-underline-preference',
93+
},
9094
] as const
9195

9296
test.describe('Button', () => {

packages/react/.storybook/preview.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,14 @@ export const decorators = [
286286

287287
// Set data-a11y-link-underlines=true to enable underlines in all stories except the Link dev Inline Story.
288288
let wrapperProps =
289-
context.id !== 'components-link-dev--inline'
289+
context.id !== 'components-link-dev--inline' ||
290+
context.id !== 'components-button-dev--link-variant-with-underline-preference'
290291
? {
291-
'data-a11y-link-underlines': context.id !== 'components-link-dev--inline',
292+
'data-a11y-link-underlines': true,
292293
className: clsx('story-wrap'),
293294
}
294295
: {className: clsx('story-wrap')}
296+
console.log('context.id', context.id)
295297
const showSurroundingElements =
296298
context.globals.showSurroundingElements ?? window.localStorage.getItem('showSurroundingElements') === 'true'
297299
return context.globals.colorScheme === 'all' ? (

packages/react/src/Button/Button.dev.stories.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,32 @@ export const DisabledButtonVariants = () => {
8585
</Stack>
8686
)
8787
}
88+
89+
export const LinkVariantWithUnderlinePreference = () => {
90+
return (
91+
<Stack gap="spacious">
92+
<Stack gap="condensed" align="start" data-a11y-link-underlines="true">
93+
<Button variant="link">Underline pref on</Button>
94+
<Button
95+
variant="link"
96+
leadingVisual={SearchIcon}
97+
trailingAction={TriangleDownIcon}
98+
trailingVisual={HeartFillIcon}
99+
>
100+
Underline pref on
101+
</Button>
102+
</Stack>
103+
<Stack gap="condensed" align="start" data-a11y-link-underlines="false">
104+
<Button variant="link">Underline pref off</Button>
105+
<Button
106+
variant="link"
107+
leadingVisual={SearchIcon}
108+
trailingAction={TriangleDownIcon}
109+
trailingVisual={HeartFillIcon}
110+
>
111+
Underline pref off
112+
</Button>
113+
</Stack>
114+
</Stack>
115+
)
116+
}

packages/react/src/Button/ButtonBase.module.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@
467467
color: var(--fgColor-link);
468468
text-align: left;
469469
border: unset;
470+
border-radius: 0;
470471

471472
&:hover:not(:disabled, [data-inactive]) {
472473
text-decoration: underline;
@@ -498,6 +499,34 @@
498499
}
499500
}
500501

502+
[data-a11y-link-underlines='true'] &:where([data-variant='link']) {
503+
&:not(:has(.Visual)) {
504+
text-decoration: underline;
505+
}
506+
507+
&:has(.Visual) {
508+
background-image: linear-gradient(to right, currentColor, currentColor);
509+
background-size: 100% 1.5px;
510+
background-position: 0 calc(100% - 2px);
511+
background-repeat: no-repeat;
512+
513+
&:hover {
514+
text-decoration: none;
515+
}
516+
}
517+
}
518+
519+
[data-a11y-link-underlines='false'] &:where([data-variant='link']) {
520+
&:not(:has(.Visual)) {
521+
text-decoration: none;
522+
background-image: none;
523+
}
524+
525+
&:has(.Visual) {
526+
background-image: none;
527+
}
528+
}
529+
501530
/* Inactive */
502531

503532
&:where([data-inactive]),

0 commit comments

Comments
 (0)