Skip to content

Commit 7118312

Browse files
committed
fix(ui-buttons): remove underline from disabled Button with href
INSTUI-4540
1 parent 23be361 commit 7118312

File tree

4 files changed

+43
-23
lines changed

4 files changed

+43
-23
lines changed

packages/ui-buttons/src/BaseButton/__new-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
@@ -88,7 +88,8 @@ class BaseButton extends Component<BaseButtonProps> {
8888
get makeStylesVariables(): BaseButtonStyleProps {
8989
return {
9090
isDisabled: this.isDisabled,
91-
hasOnlyIconVisible: this.hasOnlyIconVisible
91+
hasOnlyIconVisible: this.hasOnlyIconVisible,
92+
isEnabled: this.isEnabled
9293
}
9394
}
9495

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

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

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)