Skip to content

Commit 37738e5

Browse files
fix: add missing Select semantic names (ant-design#56322)
* fix: add missing Select semantic names * update tests * conditional expects 🙃 * consistency * chore: adjust code --------- Co-authored-by: 遇见同学 <1875694521@qq.com>
1 parent b3854ca commit 37738e5

3 files changed

Lines changed: 49 additions & 8 deletions

File tree

.dumi/theme/common/SelectSemanticTemplate.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const locales = {
1111
suffix: '后缀元素,包含后缀内容的布局和样式,如清除按钮、箭头图标等',
1212
input: '输入框元素,包含搜索输入框的样式、光标控制、字体继承等搜索相关样式,去除了边框样式',
1313
content: '多选容器,包含已选项的布局、间距、换行相关样式',
14+
clear: '清除按钮元素,包含清除按钮的布局、样式和交互效果',
1415
item: '多选项元素,包含边框、背景、内边距、外边距样式',
1516
itemContent: '多选项内容区域,包含文字的省略样式',
1617
itemRemove: '多选项移除按钮,包含字体相关样式',
@@ -29,6 +30,7 @@ export const locales = {
2930
'Input element with search input styling, cursor control, font inheritance and other search-related styles. Remove border styles',
3031
content:
3132
'Multiple selection container with layout, spacing, and wrapping styles for selected items',
33+
clear: 'Clear button element with layout, styling and interactive effects for clear button',
3234
item: 'Multiple selection item element with border, background, padding, and margin styles',
3335
itemContent: 'Multiple selection item content area with text ellipsis styles',
3436
itemRemove: 'Multiple selection item remove button with font-related styles',
@@ -142,6 +144,7 @@ const SelectSemanticTemplate: React.FC<SelectSemanticTemplateProps> = ({
142144
{ name: 'prefix', desc: locale.prefix },
143145
{ name: 'content', desc: locale.content },
144146
{ name: 'placeholder', desc: locale.placeholder },
147+
{ name: 'clear', desc: locale.clear },
145148
{ name: 'input', desc: locale.input },
146149
{ name: 'suffix', desc: locale.suffix },
147150
{ name: 'popup.root', desc: locale['popup.root'] },
@@ -152,11 +155,12 @@ const SelectSemanticTemplate: React.FC<SelectSemanticTemplateProps> = ({
152155
{ name: 'root', desc: locale.root },
153156
{ name: 'prefix', desc: locale.prefix },
154157
{ name: 'content', desc: locale.content },
158+
{ name: 'placeholder', desc: locale.placeholder },
159+
{ name: 'clear', desc: locale.clear },
155160
{ name: 'item', desc: locale.item },
156161
{ name: 'itemContent', desc: locale.itemContent },
157162
{ name: 'itemRemove', desc: locale.itemRemove },
158163
{ name: 'input', desc: locale.input },
159-
{ name: 'placeholder', desc: locale.placeholder },
160164
{ name: 'suffix', desc: locale.suffix },
161165
{ name: 'popup.root', desc: locale['popup.root'] },
162166
{ name: 'popup.list', desc: locale['popup.list'] },

components/select/__tests__/semantic.test.tsx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22

33
import Select from '..';
4-
import type { SelectProps } from '..';
4+
import type { SelectClassNamesType, SelectProps } from '..';
55
import { render } from '../../../tests/utils';
66

77
describe('Select.Semantic', () => {
@@ -28,7 +28,7 @@ describe('Select.Semantic', () => {
2828
list: 'custom-list',
2929
listItem: 'custom-list-item',
3030
},
31-
};
31+
} satisfies SelectClassNamesType;
3232
const styles = {
3333
root: { color: 'rgb(255, 0, 0)' },
3434
prefix: { color: 'rgb(0, 128, 255)' },
@@ -60,9 +60,9 @@ describe('Select.Semantic', () => {
6060
expect(container.querySelector(`.${classNames.placeholder}`)).toHaveStyle(styles.placeholder);
6161
expect(container.querySelector(`.${classNames.input}`)).toHaveStyle(styles.input);
6262
expect(container.querySelector(`.${classNames.content}`)).toHaveStyle(styles.content);
63-
expect(container.querySelector(`.${classNames.popup.root}`)).toHaveStyle(styles.popup.root);
64-
expect(container.querySelector(`.${classNames.popup.list}`)).toHaveStyle(styles.popup.list);
65-
expect(container.querySelector(`.${classNames.popup.listItem}`)).toHaveStyle(
63+
expect(container.querySelector(`.${classNames.popup?.root}`)).toHaveStyle(styles.popup.root);
64+
expect(container.querySelector(`.${classNames.popup?.list}`)).toHaveStyle(styles.popup.list);
65+
expect(container.querySelector(`.${classNames.popup?.listItem}`)).toHaveStyle(
6666
styles.popup.listItem,
6767
);
6868
});
@@ -72,16 +72,22 @@ describe('Select.Semantic', () => {
7272
root: 'custom-root',
7373
prefix: 'custom-prefix',
7474
suffix: 'custom-suffix',
75+
item: 'custom-item',
76+
itemContent: 'custom-item-content',
77+
itemRemove: 'custom-item-remove',
7578
popup: {
7679
root: 'custom-popup',
7780
list: 'custom-list',
7881
listItem: 'custom-list-item',
7982
},
80-
};
83+
} satisfies SelectClassNamesType;
8184
const customStyles = {
8285
root: { color: 'rgb(255, 0, 0)' },
8386
prefix: { color: 'rgb(0, 128, 255)' },
8487
suffix: { color: 'rgb(255, 128, 0)' },
88+
item: { background: 'rgb(255, 255, 240)' },
89+
itemContent: { color: 'rgb(128, 0, 128)' },
90+
itemRemove: { color: 'rgb(255, 0, 0)' },
8591
popup: {
8692
root: { color: 'rgb(128, 0, 128)' },
8793
list: { color: 'rgb(0, 0, 255)' },
@@ -107,6 +113,9 @@ describe('Select.Semantic', () => {
107113
const list = container.querySelector('.rc-virtual-list');
108114
const listItem = container.querySelector('.ant-select-item');
109115
const popup = container.querySelector('.ant-select-dropdown');
116+
const item = container.querySelector('.ant-select-selection-item');
117+
const itemContent = container.querySelector('.ant-select-selection-item-content');
118+
const itemRemove = container.querySelector('.ant-select-selection-item-remove');
110119

111120
expect(root).toHaveClass(customClassNames.root);
112121
expect(prefix).toHaveClass(customClassNames.prefix);
@@ -120,6 +129,15 @@ describe('Select.Semantic', () => {
120129
if (popup) {
121130
expect(popup).toHaveClass(customClassNames.popup.root);
122131
}
132+
if (item) {
133+
expect(item).toHaveClass(customClassNames.item);
134+
}
135+
if (itemContent) {
136+
expect(itemContent).toHaveClass(customClassNames.itemContent);
137+
}
138+
if (itemRemove) {
139+
expect(itemRemove).toHaveClass(customClassNames.itemRemove);
140+
}
123141

124142
expect(root).toHaveStyle(customStyles.root);
125143
expect(prefix).toHaveStyle(customStyles.prefix);
@@ -133,6 +151,15 @@ describe('Select.Semantic', () => {
133151
if (popup) {
134152
expect(popup).toHaveStyle(customStyles.popup.root);
135153
}
154+
if (item) {
155+
expect(item).toHaveStyle(customStyles.item);
156+
}
157+
if (itemContent) {
158+
expect(itemContent).toHaveStyle(customStyles.itemContent);
159+
}
160+
if (itemRemove) {
161+
expect(itemRemove).toHaveStyle(customStyles.itemRemove);
162+
}
136163
});
137164

138165
it('should support function-based classNames and styles', () => {

components/select/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,17 @@ export interface InternalSelectProps<
7676
styles?: SemanticStyles<SemanticName> & { popup?: SemanticStyles<PopupSemantic> };
7777
}
7878

79-
type SemanticName = 'root' | 'prefix' | 'suffix';
79+
type SemanticName =
80+
| 'root'
81+
| 'prefix'
82+
| 'suffix'
83+
| 'input'
84+
| 'placeholder'
85+
| 'content'
86+
| 'item'
87+
| 'itemContent'
88+
| 'itemRemove'
89+
| 'clear';
8090

8191
type PopupSemantic = 'root' | 'listItem' | 'list';
8292

0 commit comments

Comments
 (0)