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): improve empty options styling and messaging for Select (#3569)

白熱37627064d19a
diff --git a/packages/design/src/components/select/Select.stories.tsx b/packages/design/src/components/select/Select.stories.tsx
index cd02ae672d..95d338aad6 100644
--- a/packages/design/src/components/select/Select.stories.tsx
+++ b/packages/design/src/components/select/Select.stories.tsx
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-import type { Meta } from '@storybook/react';
import React, { useState } from 'react';
+import type { Meta } from '@storybook/react';
import { Select } from './Select';
+import type { ISelectProps } from './Select';
const meta: Meta<typeof Select> = {
title: 'Components / Select',
@@ -48,6 +49,20 @@ export const SelectBasic = {
},
};
+export const SelectEmpty = {
+ render() {
+ const [value, setValue] = useState('');
+
+ const options: ISelectProps['options'] = [];
+
+ function handleChange(value: string | number | boolean) {
+ setValue(value as string);
+ }
+
+ return <Select value={value} options={options} onChange={handleChange} />;
+ },
+};
+
export const SelectBorderless = {
render() {
const [value, setValue] = useState('');
diff --git a/packages/design/src/components/select/Select.tsx b/packages/design/src/components/select/Select.tsx
index 1b4074ae23..a161c4227d 100644
--- a/packages/design/src/components/select/Select.tsx
+++ b/packages/design/src/components/select/Select.tsx
@@ -15,11 +15,11 @@
*/
import { MoreDownSingle } from '@univerjs/icons';
+import clsx from 'clsx';
import RcSelect from 'rc-select';
-import React, { useContext } from 'react';
+import React, { useContext } from 'react';
import type { LabelInValueType } from 'rc-select/lib/Select';
-import clsx from 'clsx';
import { ConfigContext } from '../config-provider/ConfigProvider';
import styles from './index.module.less';
@@ -92,7 +92,7 @@ export function Select(props: ISelectProps) {
disabled,
} = props;
- const { mountContainer } = useContext(ConfigContext);
+ const { mountContainer, locale } = useContext(ConfigContext);
const _className = clsx(className, {
[styles.selectBorderless]: borderless,
@@ -115,6 +115,7 @@ export function Select(props: ISelectProps) {
open={open}
dropdownStyle={dropdownStyle}
onDropdownVisibleChange={onDropdownVisibleChange}
+ notFoundContent={locale?.Select.empty}
disabled={disabled}
/>
);
diff --git a/packages/design/src/components/select/index.module.less b/packages/design/src/components/select/index.module.less
index beb04dd1b4..5990f6424b 100644
--- a/packages/design/src/components/select/index.module.less
+++ b/packages/design/src/components/select/index.module.less
@@ -34,7 +34,7 @@
height: 12px;
margin-top: 4px;
- border: 2px solid #999;
+ border: 2px solid rgb(var(--border-color));
border-top-color: transparent;
border-bottom-color: transparent;
border-radius: 100%;
@@ -238,7 +238,7 @@
height: 0;
border: 5px solid transparent;
- border-top-color: #999;
+ border-top-color: rgb(var(--border-color));
}
}
}
@@ -307,13 +307,15 @@
// ------ Disabled ------
&-disabled {
- color: #999;
+ color: rgb(var(--text-color-tertiary));
}
}
// >>> Empty
&-empty {
- color: #999;
+ padding: var(--padding-xs) 0;
+ color: rgb(var(--text-color-tertiary));
+ font-size: var(--font-size-sm);
text-align: center;
}
}
diff --git a/packages/design/src/locale/en-US.ts b/packages/design/src/locale/en-US.ts
index fe8b3d903a..353c7bca75 100644
--- a/packages/design/src/locale/en-US.ts
+++ b/packages/design/src/locale/en-US.ts
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import PickerEnUs from 'rc-picker/lib/locale/en_US';
import dajsEnUS from 'dayjs/locale/en';
+import PickerEnUs from 'rc-picker/lib/locale/en_US';
import type { ILocale } from './interface';
const locale: ILocale = {
@@ -34,6 +34,9 @@ const locale: ILocale = {
CascaderList: {
empty: 'None',
},
+ Select: {
+ empty: 'None',
+ },
},
};
diff --git a/packages/design/src/locale/interface.ts b/packages/design/src/locale/interface.ts
index 01858ededd..2629080846 100644
--- a/packages/design/src/locale/interface.ts
+++ b/packages/design/src/locale/interface.ts
@@ -22,5 +22,6 @@ export interface ILocale {
Slider: Record<string, any>;
Picker: typeof PickerZhCN;
CascaderList: Record<string, any>;
+ Select: Record<string, any>;
};
}
diff --git a/packages/design/src/locale/ru-RU.ts b/packages/design/src/locale/ru-RU.ts
index 4074f9285d..6c19c4610d 100644
--- a/packages/design/src/locale/ru-RU.ts
+++ b/packages/design/src/locale/ru-RU.ts
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import PickerRuRU from 'rc-picker/lib/locale/ru_RU';
import dajsRuRU from 'dayjs/locale/ru';
+import PickerRuRU from 'rc-picker/lib/locale/ru_RU';
import type { ILocale } from './interface';
const locale: ILocale = {
@@ -34,6 +34,9 @@ const locale: ILocale = {
CascaderList: {
empty: 'Нет',
},
+ Select: {
+ empty: 'Нет',
+ },
},
};
diff --git a/packages/design/src/locale/vi-VN.ts b/packages/design/src/locale/vi-VN.ts
index 7f4fa5d52f..cb7b12b13e 100644
--- a/packages/design/src/locale/vi-VN.ts
+++ b/packages/design/src/locale/vi-VN.ts
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import PickerViVN from 'rc-picker/lib/locale/vi_VN';
import dajsViVN from 'dayjs/locale/vi';
+import PickerViVN from 'rc-picker/lib/locale/vi_VN';
import type { ILocale } from './interface';
const locale: ILocale = {
@@ -34,8 +34,10 @@ const locale: ILocale = {
CascaderList: {
empty: 'Không có',
},
+ Select: {
+ empty: 'Không có',
+ },
},
-
};
export default locale;
diff --git a/packages/design/src/locale/zh-CN.ts b/packages/design/src/locale/zh-CN.ts
index 25e7446119..a2caae5ccd 100644
--- a/packages/design/src/locale/zh-CN.ts
+++ b/packages/design/src/locale/zh-CN.ts
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import PickerZhCN from 'rc-picker/lib/locale/zh_CN';
import dajsZhCN from 'dayjs/locale/zh';
+import PickerZhCN from 'rc-picker/lib/locale/zh_CN';
import type { ILocale } from './interface';
const locale: ILocale = {
@@ -34,6 +34,9 @@ const locale: ILocale = {
CascaderList: {
empty: '无',
},
+ Select: {
+ empty: '无',
+ },
},
};
diff --git a/packages/design/src/locale/zh-TW.ts b/packages/design/src/locale/zh-TW.ts
index 2e7e9b33eb..ffe5d64abc 100644
--- a/packages/design/src/locale/zh-TW.ts
+++ b/packages/design/src/locale/zh-TW.ts
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import PickerZhTw from 'rc-picker/lib/locale/zh_TW';
import dajsZhTw from 'dayjs/locale/zh-tw';
+import PickerZhTw from 'rc-picker/lib/locale/zh_TW';
import type { ILocale } from './interface';
const locale: ILocale = {
@@ -34,6 +34,9 @@ const locale: ILocale = {
CascaderList: {
empty: '無',
},
+ Select: {
+ empty: '無',
+ },
},
};