Skip to content

fix(checkbox): 列表模式切换选中态,布局错误 #3166

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

Open
wants to merge 3 commits into
base: feat_v3.x
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`should match snapshot 1`] = `
class="nut-checkbox nut-checkbox-reverse"
>
<div
class="nut-checkbox-icon-wrap"
class="nut-checkbox-icon-wrap-shadow"
>
<svg
aria-labelledby="Checked"
Expand Down
7 changes: 6 additions & 1 deletion src/packages/checkbox/checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
flex-shrink: 0;
}

&-icon-wrap {
&-icon-wrap-shadow {
font-size: 0px;
line-height: 0px;
border-radius: 50%;
box-shadow: 0px 2px 4px 0px rgba(255, 15, 35, 0.2);
}
&-icon-wrap {
font-size: 0px;
line-height: 0px;
border-radius: 50%;
}

&-icon-checked {
color: $color-primary;
Expand Down
36 changes: 26 additions & 10 deletions src/packages/checkbox/checkbox.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC, useContext, useEffect, useState } from 'react'
import { CheckDisabled, Checked, CheckNormal } from '@nutui/icons-react-taro'
import classNames from 'classnames'
import { CheckboxProps as TCheckboxProps, View } from '@tarojs/components'
import { CheckboxProps as TCheckboxProps, Text, View } from '@tarojs/components'
import { ComponentDefaults } from '@/utils/typings'
import Context from '../checkboxgroup/context'
import { usePropsValue } from '@/hooks/use-props-value'
Expand Down Expand Up @@ -79,31 +79,47 @@ export const Checkbox: FC<
const renderIcon = () => {
if (innerDisabled) {
if (innerIndeterminate) {
return <CheckDisabled className={color()} />
return (
<View className={`${classPrefix}-icon-wrap`}>
<CheckDisabled className={color()} />
</View>
)
}
if (innerChecked) {
return <Checked className={color()} />
return (
<View className={`${classPrefix}-icon-wrap`}>
<Checked className={color()} />
</View>
)
}
return <CheckDisabled className={color()} />
return (
<View className={`${classPrefix}-icon-wrap`}>
<CheckDisabled className={color()} />
</View>
)
}
if (!innerChecked) {
return React.isValidElement(icon) ? (
icon
) : (
<CheckNormal className={color()} />
<View className={`${classPrefix}-icon-wrap`}>
<CheckNormal className={color()} />
</View>
)
}
if (innerIndeterminate) {
return React.isValidElement(indeterminateIcon) ? (
indeterminateIcon
) : (
<CheckDisabled className={color()} />
<View className={`${classPrefix}-icon-wrap`}>
<CheckDisabled className={color()} />
</View>
)
}
return React.isValidElement(activeIcon) ? (
activeIcon
) : (
<View className={`${classPrefix}-icon-wrap`}>
<View className={`${classPrefix}-icon-wrap-shadow`}>
<Checked className={color()} />
</View>
)
Expand All @@ -129,13 +145,13 @@ export const Checkbox: FC<
}
const renderLabel = () => {
return (
<View
<Text
className={classNames(`${classPrefix}-label `, {
[`${classPrefix}-label-disabled`]: innerDisabled,
})}
>
{children || label}
</View>
</Text>
)
}

Expand Down Expand Up @@ -178,7 +194,7 @@ export const Checkbox: FC<

const renderCheckboxItem = () => {
if (ctx?.list) {
return <>{renderListItem()}</>
return renderListItem()
}
if (shape === 'button') {
return renderButton()
Expand Down
2 changes: 1 addition & 1 deletion src/packages/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const Checkbox: FunctionComponent<
return React.isValidElement(activeIcon) ? (
activeIcon
) : (
<div className={`${classPrefix}-icon-wrap`}>
<div className={`${classPrefix}-icon-wrap-shadow`}>
<Checked className={color()} />
</div>
)
Expand Down