Skip to content

Commit 90e8ce7

Browse files
committed
fix(ui-buttons): remove underline from disabled Button with href
INSTUI-4540
1 parent 0f7ffa5 commit 90e8ce7

File tree

4 files changed

+43
-23
lines changed

4 files changed

+43
-23
lines changed

packages/ui-buttons/src/BaseButton/__tests__/BaseButton.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ describe('<BaseButton/>', () => {
192192
expect(elementRef).toBeCalledWith(button)
193193
})
194194

195+
it('should not be underlined when disabled with a href', () => {
196+
render(
197+
<BaseButton disabled href="#">
198+
Hello World
199+
</BaseButton>
200+
)
201+
const button = screen.getByRole('link', { name: 'Hello World' })
202+
203+
const styles = window.getComputedStyle(button)
204+
expect(styles.textDecoration).toContain('none')
205+
})
206+
195207
describe('onClick', () => {
196208
it('should call onClick when clicked', async () => {
197209
const onClick = vi.fn()

packages/ui-buttons/src/BaseButton/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ class BaseButton extends Component<BaseButtonProps> {
8989
get makeStylesVariables(): BaseButtonStyleProps {
9090
return {
9191
isDisabled: this.isDisabled,
92-
hasOnlyIconVisible: this.hasOnlyIconVisible
92+
hasOnlyIconVisible: this.hasOnlyIconVisible,
93+
isEnabled: this.isEnabled
9394
}
9495
}
9596

@@ -256,7 +257,7 @@ class BaseButton extends Component<BaseButtonProps> {
256257
...props
257258
} = this.props
258259

259-
const { isDisabled, isEnabled, isReadOnly, elementType } = this
260+
const { isDisabled, isReadOnly, elementType } = this
260261
// only add 0 tabIndex value if it doesn't have it by default, see
261262
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
262263
let needsZeroTabIndex = true
@@ -306,7 +307,7 @@ class BaseButton extends Component<BaseButtonProps> {
306307
role={onClick && as !== 'button' ? 'button' : undefined}
307308
tabIndex={tabIndexValue}
308309
disabled={isDisabled || isReadOnly}
309-
css={isEnabled ? styles?.baseButton : null}
310+
css={styles?.baseButton}
310311
focusRingBorderRadius={String(
311312
(styles?.content as { borderRadius?: string | number })?.borderRadius
312313
)}

packages/ui-buttons/src/BaseButton/props.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ type BaseButtonOwnProps = {
174174
type BaseButtonStyleProps = {
175175
isDisabled: boolean
176176
hasOnlyIconVisible: boolean
177+
isEnabled: boolean
177178
}
178179

179180
type PropKeys = keyof BaseButtonOwnProps

packages/ui-buttons/src/BaseButton/styles.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const generateStyle = (
5656
isCondensed
5757
} = props
5858

59-
const { isDisabled, hasOnlyIconVisible } = state
59+
const { isDisabled, hasOnlyIconVisible, isEnabled } = state
6060

6161
const shapeVariants = {
6262
circle: { borderRadius: '50%' },
@@ -401,26 +401,32 @@ const generateStyle = (
401401
}
402402

403403
return {
404-
baseButton: {
405-
label: 'baseButton',
406-
appearance: 'none',
407-
textDecoration: 'none' /* for links styled as buttons */,
408-
touchAction: 'manipulation',
409-
410-
'&::-moz-focus-inner': {
411-
border: '0' /* removes default dotted focus outline in Firefox */
412-
},
413-
'*': {
414-
pointerEvents:
415-
'none' /* Ensures that button or link is always the event target */
416-
},
417-
'&:focus': {
418-
textDecoration: 'none'
419-
},
420-
'&:active > [class$=-baseButton__content]': colorVariants[color!].active,
421-
'&:hover > [class$=-baseButton__content]': colorVariants[color!].hover
422-
},
404+
baseButton: isEnabled
405+
? {
406+
label: 'baseButton',
407+
appearance: 'none',
408+
textDecoration: 'none' /* for links styled as buttons */,
409+
touchAction: 'manipulation',
423410

411+
'&::-moz-focus-inner': {
412+
border: '0' /* removes default dotted focus outline in Firefox */
413+
},
414+
'*': {
415+
pointerEvents:
416+
'none' /* Ensures that button or link is always the event target */
417+
},
418+
'&:focus': {
419+
textDecoration: 'none'
420+
},
421+
'&:active > [class$=-baseButton__content]':
422+
colorVariants[color!].active,
423+
'&:hover > [class$=-baseButton__content]': colorVariants[color!].hover
424+
}
425+
: {
426+
textDecoration: 'none',
427+
label: 'baseButton',
428+
appearance: 'none'
429+
},
424430
content: {
425431
label: 'baseButton__content',
426432
boxSizing: 'border-box',

0 commit comments

Comments
 (0)