Skip to content

Commit

Permalink
fix(comp:button): update the link button style (#1174)
Browse files Browse the repository at this point in the history
  • Loading branch information
danranVm authored Sep 29, 2022
1 parent 464bf40 commit d21cdaa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
14 changes: 14 additions & 0 deletions packages/components/button/__tests__/button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ describe('Button', () => {
expect(wrapper.classes()).toContain('ix-button-disabled')
})

test('disabled with link mode work', async () => {
const onClick = vi.fn()
const wrapper = ButtonMount({ props: { mode: 'link', disabled: true, onClick } })

await wrapper.trigger('click')

expect(onClick).not.toBeCalled()

await wrapper.setProps({ disabled: false })
await wrapper.trigger('click')

expect(onClick).toBeCalled()
})

test('loading work', async () => {
const wrapper = ButtonMount({ props: { icon: 'up', loading: true } })

Expand Down
13 changes: 12 additions & 1 deletion packages/components/button/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export default defineComponent({
})
})

const handleLinkClick = (evt: MouseEvent) => {
if (props.disabled || props.loading) {
evt.preventDefault()
evt.stopImmediatePropagation()
}
}

return () => {
const { disabled, loading, icon, type } = props

Expand All @@ -62,7 +69,11 @@ export default defineComponent({
}

if (mode.value === 'link') {
return <a class={classes.value}>{children}</a>
return (
<a class={classes.value} onClick={handleLinkClick}>
{children}
</a>
)
}
return (
<button class={classes.value} disabled={disabled || loading} type={type}>
Expand Down
4 changes: 0 additions & 4 deletions packages/components/button/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@
&-disabled {
cursor: not-allowed;

&:not([disabled]) {
pointer-events: none;
}

> * {
pointer-events: none;
}
Expand Down
6 changes: 2 additions & 4 deletions packages/components/button/style/mixin.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
font-size: @font-size;
border-radius: @border-radius;

.@{icon-prefix} {
.@{icon-prefix} {
font-size: @icon-font-size;
}
}

.button-disabled(@color: @button-disable-color; @background: @button-disable-background-color; @border: @button-disable-border) {
&.@{button-prefix}-disabled {

&,
&:hover,
&:focus,
Expand Down Expand Up @@ -222,6 +221,7 @@

padding: 0;
min-width: 0;
text-decoration: none;

&:hover {
background: @button-link-hover-background-color;
Expand All @@ -245,7 +245,6 @@
}
}


&:active {
& when not (@theme = dark) {
.button-color(@button-danger-active-color, @button-default-background-color, @button-danger-active-border-color);
Expand All @@ -271,7 +270,6 @@
}
}


&:active {
& when not (@theme = dark) {
.button-color(~`colorPalette('@{button-danger-color}', 10) `; fadein(@button-text-hover-background-color, 1%); transparent);
Expand Down

0 comments on commit d21cdaa

Please sign in to comment.