Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(design): fix checkbox group value couldn't be modified (#1613)

白熱dcb3e934afe0
diff --git a/common/storybook/package.json b/common/storybook/package.json
index cdb6a7aef7..d7fe29c9f1 100644
--- a/common/storybook/package.json
+++ b/common/storybook/package.json
@@ -23,6 +23,7 @@
"@storybook/addon-styling-webpack": "^0.0.6",
"@storybook/addon-webpack5-compiler-swc": "^1.0.2",
"@storybook/blocks": "8.0.0",
+ "@storybook/icons": "^1.2.9",
"@storybook/react": "8.0.0",
"@storybook/react-webpack5": "8.0.0",
"@storybook/types": "^8.0.0",
diff --git a/packages/design/src/components/checkbox-group/CheckboxGroup.tsx b/packages/design/src/components/checkbox-group/CheckboxGroup.tsx
index 3106df4fb2..bf559ccb26 100644
--- a/packages/design/src/components/checkbox-group/CheckboxGroup.tsx
+++ b/packages/design/src/components/checkbox-group/CheckboxGroup.tsx
@@ -15,6 +15,7 @@
*/
import React from 'react';
+import clsx from 'clsx';
import type { ICheckboxProps } from '../checkbox/Checkbox';
import styles from './index.module.less';
@@ -22,6 +23,16 @@ import styles from './index.module.less';
export interface ICheckboxGroupProps {
children: React.ReactNode[];
+ /**
+ * The class name of the checkbox group
+ */
+ className?: string;
+
+ /**
+ * The style of the checkbox group
+ */
+ style?: React.CSSProperties;
+
/**
* Define which checkbox is selected
*/
@@ -37,15 +48,13 @@ export interface ICheckboxGroupProps {
* The callback function triggered when switching options
*/
onChange: (value: Array<string | number | boolean>) => void;
-
- style?: React.CSSProperties;
}
/**
* CheckboxGroup Component
*/
export function CheckboxGroup(props: ICheckboxGroupProps) {
- const { children, value, disabled, onChange, style } = props;
+ const { children, className, style, value, disabled, onChange } = props;
const handleChange = (item: string | number | boolean) => {
if (value.includes(item)) {
@@ -55,8 +64,10 @@ export function CheckboxGroup(props: ICheckboxGroupProps) {
}
};
+ const _className = clsx(className, styles.checkboxGroup);
+
return (
- <div className={styles.checkboxGroup} style={style}>
+ <div className={_className} style={style}>
{React.Children.map(children, (child, index) => {
if (React.isValidElement<ICheckboxProps>(child)) {
return React.cloneElement(child, {
diff --git a/packages/design/src/components/checkbox-group/__tests__/index.spec.tsx b/packages/design/src/components/checkbox-group/__tests__/index.spec.tsx
index 78e24fe22e..20198a44d3 100644
--- a/packages/design/src/components/checkbox-group/__tests__/index.spec.tsx
+++ b/packages/design/src/components/checkbox-group/__tests__/index.spec.tsx
@@ -62,6 +62,6 @@ describe('CheckboxGroup', () => {
fireEvent.click(getByText('y'));
fireEvent.click(getByText('y'));
- expect(result).toEqual(['0', false]);
+ expect(result).toEqual(['0', '1']);
});
});
diff --git a/packages/design/src/components/checkbox/Checkbox.tsx b/packages/design/src/components/checkbox/Checkbox.tsx
index d142f30ff6..e6a3bb2320 100644
--- a/packages/design/src/components/checkbox/Checkbox.tsx
+++ b/packages/design/src/components/checkbox/Checkbox.tsx
@@ -22,6 +22,16 @@ import styles from './index.module.less';
export interface ICheckboxProps {
children?: React.ReactNode;
+ /**
+ * The class name of the checkbox group
+ */
+ className?: string;
+
+ /**
+ * The style of the checkbox group
+ */
+ style?: React.CSSProperties;
+
/**
* Used for setting the currently selected value
* @default false
@@ -43,15 +53,13 @@ export interface ICheckboxProps {
* Set the handler to handle `click` event
*/
onChange?: (value: string | number | boolean) => void;
-
- style?: React.CSSProperties;
}
/**
* Checkbox Component
*/
export function Checkbox(props: ICheckboxProps) {
- const { children, checked, value, disabled = false, onChange, style } = props;
+ const { children, className, style, checked, value, disabled = false, onChange } = props;
const inputRef = useRef<HTMLInputElement>(null);
@@ -61,14 +69,14 @@ export function Checkbox(props: ICheckboxProps) {
if (!onChange || disabled) return;
if (typeof value !== 'undefined') {
- onChange?.(!value);
+ onChange?.(value);
} else {
const checked = inputRef?.current?.checked!;
onChange?.(!checked);
}
}
- const _className = clsx(styles.checkbox, {
+ const _className = clsx(className, styles.checkbox, {
[styles.checkboxDisabled]: disabled,
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index eed55340c6..eb74ca94d5 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -131,6 +131,9 @@ importers:
'@storybook/blocks':
specifier: 8.0.0
+ '@storybook/icons':
+ specifier: ^1.2.9
'@storybook/react':
specifier: 8.0.0
@@ -4123,7 +4126,7 @@ packages:
'@storybook/csf': 0.1.2
'@storybook/docs-tools': 8.0.0
'@storybook/global': 5.0.0
- '@storybook/icons': 1.2.5([email protected])([email protected])
+ '@storybook/icons': 1.2.9([email protected])([email protected])
'@storybook/manager-api': 8.0.0([email protected])([email protected])
'@storybook/preview-api': 8.0.0
'@storybook/theming': 8.0.0([email protected])([email protected])
@@ -4319,7 +4322,7 @@ packages:
'@storybook/client-logger': 8.0.0
'@storybook/csf': 0.1.2
'@storybook/global': 5.0.0
- '@storybook/icons': 1.2.5([email protected])([email protected])
+ '@storybook/icons': 1.2.9([email protected])([email protected])
'@storybook/theming': 8.0.0([email protected])([email protected])
'@storybook/types': 8.0.0
memoizerific: 1.11.3
@@ -4488,8 +4491,8 @@ packages:
/@storybook/[email protected]:
resolution: {integrity: sha512-FcOqPAXACP0I3oJ/ws6/rrPT9WGhu915Cg8D02a9YxLo0DE9zI+a9A5gRGvmQ09fiWPukqI8ZAEoQEdWUKMQdQ==}
- resolution: {integrity: sha512-m3jnuE+zmkZy6K+cdUDzAoUuCJyl0fWCAXPCji7VZCH1TzFohyvnPqhc9JMkQpanej2TOW3wWXaplPzHghcBSg==}
+ resolution: {integrity: sha512-cOmylsz25SYXaJL/gvTk/dl3pyk7yBFRfeXTsHvTA3dfhoU/LWSq0NKL9nM7WBasJyn6XPSGnLS4RtKXLw5EUg==}
engines: {node: '>=14.0.0'}
peerDependencies:
react: ^16.8.0 || ^17.0.0 || ^18.0.0