Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(checkbox): add checkbox-input style to solve the problem of chec… #2125

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
56 changes: 29 additions & 27 deletions packages/web-vue/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,33 +208,35 @@ export default defineComponent({

return () => (
<label aria-disabled={mergedDisabled.value} class={cls.value}>
<input
ref={checkboxRef}
type="checkbox"
checked={computedChecked.value}
value={props.value}
class={`${prefixCls}-target`}
disabled={mergedDisabled.value}
onClick={handleClick}
onChange={handleChange}
onFocus={handleFocus}
onBlur={handleBlur}
/>
{(slots.checkbox ?? checkboxGroupCtx?.slots?.checkbox)?.({
checked: computedChecked.value,
disabled: mergedDisabled.value,
}) ?? (
<IconHover
class={`${prefixCls}-icon-hover`}
disabled={mergedDisabled.value || computedChecked.value}
>
<div class={`${prefixCls}-icon`}>
{computedChecked.value && (
<IconCheck class={`${prefixCls}-icon-check`} />
)}
</div>
</IconHover>
)}
<span class={`${prefixCls}-input`}>
<input
ref={checkboxRef}
type="checkbox"
checked={computedChecked.value}
value={props.value}
class={`${prefixCls}-target`}
disabled={mergedDisabled.value}
onClick={handleClick}
onChange={handleChange}
onFocus={handleFocus}
onBlur={handleBlur}
/>
{(slots.checkbox ?? checkboxGroupCtx?.slots?.checkbox)?.({
checked: computedChecked.value,
disabled: mergedDisabled.value,
}) ?? (
<IconHover
class={`${prefixCls}-icon-hover`}
disabled={mergedDisabled.value || computedChecked.value}
>
<div class={`${prefixCls}-icon`}>
{computedChecked.value && (
<IconCheck class={`${prefixCls}-icon-check`} />
)}
</div>
</IconHover>
)}
</span>
{slots.default && (
<span class={`${prefixCls}-label`}>{slots.default()}</span>
)}
Expand Down
46 changes: 28 additions & 18 deletions packages/web-vue/components/checkbox/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
line-height: unset;
cursor: pointer;

> input[type='checkbox'] {
&-input {
position: relative;
display: inline-flex;
white-space: nowrap;
outline: none;
cursor: pointer;
}

&-input > input[type='checkbox'] {
position: absolute;
top: 0;
left: 0;
Expand All @@ -27,8 +35,10 @@
}

&:hover {
.@{checkbox-prefix-cls}-icon-hover::before {
background-color: @checkbox-mask-bg-color-bg;
> .@{checkbox-prefix-cls}-input {
.@{checkbox-prefix-cls}-icon-hover::before {
background-color: @checkbox-mask-bg-color-bg;
}
}
}

Expand Down Expand Up @@ -74,20 +84,20 @@
}
}

&:hover &-icon {
&:hover > &-input &-icon {
border-color: @checkbox-mask-color-border_hover;
transition: border-color @transition-duration-1
@transition-timing-function-linear,
transform @transition-duration-3 @transition-timing-function-overshoot;
}

&-checked:hover &-icon,
&-indeterminate:hover &-icon {
&-checked:hover > &-input &-icon,
&-indeterminate:hover > &-input &-icon {
transition: transform @transition-duration-3
@transition-timing-function-overshoot;
}

&-checked &-icon {
&-checked > &-input &-icon {
background-color: @checkbox-mask-color-bg_checked;
border-color: @checkbox-mask-color-border_checked;

Expand All @@ -98,7 +108,7 @@
}
}

&-indeterminate &-icon {
&-indeterminate > &-input &-icon {
background-color: @checkbox-mask-color-bg_checked;
border-color: @checkbox-mask-color-border_checked;

Expand All @@ -116,48 +126,48 @@
&&-disabled {
cursor: not-allowed;

.@{checkbox-prefix-cls}-icon-hover {
> .@{checkbox-prefix-cls}-input .@{checkbox-prefix-cls}-icon-hover {
cursor: not-allowed;
}

&:hover .@{checkbox-prefix-cls}-mask {
&:hover > .@{checkbox-prefix-cls}-input .@{checkbox-prefix-cls}-mask {
border-color: @checkbox-mask-color-border_disabled;
}
}

&-checked:hover &-icon,
&-indeterminate:hover &-icon {
&-checked:hover > &-input &-icon,
&-indeterminate:hover > &-input &-icon {
border-color: @checkbox-mask-color-border_checked;
}

&-disabled &-icon {
&-disabled > &-input &-icon {
background-color: @checkbox-mask-color-bg_disabled;
border-color: @checkbox-mask-color-border_disabled;
}

&-disabled&-checked &-icon,
&-disabled&-checked:hover &-icon {
&-disabled&-checked > &-input &-icon,
&-disabled&-checked:hover > &-input &-icon {
background-color: @checkbox-mask-color-bg_checked_disabled;
border-color: @checkbox-mask-color-border_checked_disabled;
}

&-disabled:hover,
&-checked:hover,
&-indeterminate:hover {
.@{checkbox-prefix-cls}-icon-hover::before {
> @{checkbox-prefix-cls}-input .@{checkbox-prefix-cls}-icon-hover::before {
background-color: @color-transparent;
}
}

&-disabled:hover &-icon {
&-disabled:hover > &-input &-icon {
border-color: @checkbox-mask-color-border;
}

&-disabled &-label {
color: @checkbox-color-text_disabled;
}

&-disabled &-icon-check {
&-disabled > &-input &-icon-check {
color: @checkbox-color-check-icon_disabled;
}
}
Expand Down