Skip to content
Merged
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
12 changes: 12 additions & 0 deletions packages/ui-buttons/src/BaseButton/__tests__/BaseButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ describe('<BaseButton/>', () => {
expect(elementRef).toBeCalledWith(button)
})

it('should not be underlined when disabled with a href', () => {
render(
<BaseButton disabled href="#">
Hello World
</BaseButton>
)
const button = screen.getByRole('link', { name: 'Hello World' })

const styles = window.getComputedStyle(button)
expect(styles.textDecoration).toContain('none')
})

describe('onClick', () => {
it('should call onClick when clicked', async () => {
const onClick = vi.fn()
Expand Down
7 changes: 4 additions & 3 deletions packages/ui-buttons/src/BaseButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class BaseButton extends Component<BaseButtonProps> {
get makeStylesVariables(): BaseButtonStyleProps {
return {
isDisabled: this.isDisabled,
hasOnlyIconVisible: this.hasOnlyIconVisible
hasOnlyIconVisible: this.hasOnlyIconVisible,
isEnabled: this.isEnabled
}
}

Expand Down Expand Up @@ -256,7 +257,7 @@ class BaseButton extends Component<BaseButtonProps> {
...props
} = this.props

const { isDisabled, isEnabled, isReadOnly, elementType } = this
const { isDisabled, isReadOnly, elementType } = this
// only add 0 tabIndex value if it doesn't have it by default, see
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
let needsZeroTabIndex = true
Expand Down Expand Up @@ -306,7 +307,7 @@ class BaseButton extends Component<BaseButtonProps> {
role={onClick && as !== 'button' ? 'button' : undefined}
tabIndex={tabIndexValue}
disabled={isDisabled || isReadOnly}
css={isEnabled ? styles?.baseButton : null}
css={styles?.baseButton}
focusRingBorderRadius={String(
(styles?.content as { borderRadius?: string | number })?.borderRadius
)}
Expand Down
1 change: 1 addition & 0 deletions packages/ui-buttons/src/BaseButton/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ type BaseButtonOwnProps = {
type BaseButtonStyleProps = {
isDisabled: boolean
hasOnlyIconVisible: boolean
isEnabled: boolean
}

type PropKeys = keyof BaseButtonOwnProps
Expand Down
46 changes: 26 additions & 20 deletions packages/ui-buttons/src/BaseButton/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const generateStyle = (
isCondensed
} = props

const { isDisabled, hasOnlyIconVisible } = state
const { isDisabled, hasOnlyIconVisible, isEnabled } = state

const shapeVariants = {
circle: { borderRadius: '50%' },
Expand Down Expand Up @@ -401,26 +401,32 @@ const generateStyle = (
}

return {
baseButton: {
label: 'baseButton',
appearance: 'none',
textDecoration: 'none' /* for links styled as buttons */,
touchAction: 'manipulation',

'&::-moz-focus-inner': {
border: '0' /* removes default dotted focus outline in Firefox */
},
'*': {
pointerEvents:
'none' /* Ensures that button or link is always the event target */
},
'&:focus': {
textDecoration: 'none'
},
'&:active > [class$=-baseButton__content]': colorVariants[color!].active,
'&:hover > [class$=-baseButton__content]': colorVariants[color!].hover
},
baseButton: isEnabled
? {
label: 'baseButton',
appearance: 'none',
textDecoration: 'none' /* for links styled as buttons */,
touchAction: 'manipulation',

'&::-moz-focus-inner': {
border: '0' /* removes default dotted focus outline in Firefox */
},
'*': {
pointerEvents:
'none' /* Ensures that button or link is always the event target */
},
'&:focus': {
textDecoration: 'none'
},
'&:active > [class$=-baseButton__content]':
colorVariants[color!].active,
'&:hover > [class$=-baseButton__content]': colorVariants[color!].hover
}
: {
textDecoration: 'none',
label: 'baseButton',
appearance: 'none'
},
content: {
label: 'baseButton__content',
boxSizing: 'border-box',
Expand Down
Loading