Skip to content

Commit 9696629

Browse files
committed
chore: pass rc-select semantic
1 parent d65883d commit 9696629

File tree

2 files changed

+155
-11
lines changed

2 files changed

+155
-11
lines changed

src/TreeSelect.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { BaseSelectPropsWithoutPrivate, BaseSelectRef } from '@rc-component/select';
2+
import type { BaseSelectSemanticName } from '@rc-component/select/lib/BaseSelect';
23
import { BaseSelect } from '@rc-component/select';
34
import useId from '@rc-component/util/lib/hooks/useId';
45
import type { IconType } from '@rc-component/tree/lib/interface';
@@ -36,7 +37,7 @@ import type {
3637
} from './interface';
3738
import useSearchConfig from './hooks/useSearchConfig';
3839

39-
export type SemanticName = 'input' | 'prefix' | 'suffix';
40+
export type SemanticName = BaseSelectSemanticName;
4041
export type PopupSemantic = 'item' | 'itemTitle';
4142
export interface SearchConfig {
4243
searchValue?: string;
@@ -736,16 +737,8 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
736737
<BaseSelect
737738
ref={ref}
738739
{...restProps}
739-
classNames={{
740-
prefix: treeSelectClassNames?.prefix,
741-
suffix: treeSelectClassNames?.suffix,
742-
input: treeSelectClassNames?.input,
743-
}}
744-
styles={{
745-
prefix: styles?.prefix,
746-
suffix: styles?.suffix,
747-
input: styles?.input,
748-
}}
740+
classNames={treeSelectClassNames}
741+
styles={styles}
749742
// >>> MISC
750743
id={mergedId}
751744
prefixCls={prefixCls}

tests/Select.semantic.spec.tsx

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import React from 'react';
2+
import { render } from '@testing-library/react';
3+
import TreeSelect, { TreeNode } from '../src';
4+
5+
describe('TreeSelect.semantic', () => {
6+
const createSingleSelect = (props = {}) => (
7+
<TreeSelect {...props}>
8+
<TreeNode value="0" title="Node 0" key="0">
9+
<TreeNode value="0-0" title="Node 0-0" key="0-0" />
10+
<TreeNode value="0-1" title="Node 0-1" key="0-1" />
11+
</TreeNode>
12+
<TreeNode value="1" title="Node 1" key="1" />
13+
</TreeSelect>
14+
);
15+
16+
const createMultipleSelect = (props = {}) => (
17+
<TreeSelect multiple {...props}>
18+
<TreeNode value="0" title="Node 0" key="0">
19+
<TreeNode value="0-0" title="Node 0-0" key="0-0" />
20+
<TreeNode value="0-1" title="Node 0-1" key="0-1" />
21+
</TreeNode>
22+
<TreeNode value="1" title="Node 1" key="1" />
23+
</TreeSelect>
24+
);
25+
26+
it('should support semantic classNames and styles in single mode', () => {
27+
const classNames = {
28+
prefix: 'custom-prefix',
29+
suffix: 'custom-suffix',
30+
input: 'custom-input',
31+
clear: 'custom-clear',
32+
placeholder: 'custom-placeholder',
33+
content: 'custom-content',
34+
};
35+
36+
const styles = {
37+
prefix: { color: 'red' },
38+
suffix: { color: 'blue' },
39+
input: { backgroundColor: 'yellow' },
40+
clear: { fontSize: '14px' },
41+
placeholder: { fontStyle: 'italic' },
42+
content: { fontWeight: 'bold' },
43+
};
44+
45+
const { container } = render(
46+
createSingleSelect({
47+
value: '0',
48+
prefix: <span>Prefix</span>,
49+
suffix: <span>Suffix</span>,
50+
allowClear: true,
51+
placeholder: 'Please select',
52+
classNames,
53+
styles,
54+
}),
55+
);
56+
57+
// Test prefix
58+
const prefixElement = container.querySelector(`.${classNames.prefix}`);
59+
expect(prefixElement).toBeTruthy();
60+
expect(prefixElement).toHaveStyle(styles.prefix);
61+
62+
// Test suffix
63+
const suffixElement = container.querySelector(`.${classNames.suffix}`);
64+
expect(suffixElement).toBeTruthy();
65+
expect(suffixElement).toHaveStyle(styles.suffix);
66+
67+
// Test content
68+
const contentElement = container.querySelector(`.${classNames.content}`);
69+
expect(contentElement).toBeTruthy();
70+
expect(contentElement).toHaveStyle(styles.content);
71+
72+
// Test clear
73+
const clearElement = container.querySelector(`.${classNames.clear}`);
74+
expect(clearElement).toBeTruthy();
75+
expect(clearElement).toHaveStyle(styles.clear);
76+
});
77+
78+
it('should support semantic classNames and styles in multiple mode', () => {
79+
const classNames = {
80+
prefix: 'custom-prefix',
81+
suffix: 'custom-suffix',
82+
content: 'custom-content',
83+
clear: 'custom-clear',
84+
item: 'custom-item',
85+
itemContent: 'custom-item-content',
86+
itemRemove: 'custom-item-remove',
87+
};
88+
89+
const styles = {
90+
prefix: { color: 'red' },
91+
suffix: { color: 'blue' },
92+
content: { fontWeight: 'bold' },
93+
clear: { fontSize: '14px' },
94+
item: { border: '1px solid green' },
95+
itemContent: { padding: '4px' },
96+
itemRemove: { color: 'orange' },
97+
};
98+
99+
const { container } = render(
100+
createMultipleSelect({
101+
value: ['0', '1'],
102+
prefix: <span>Prefix</span>,
103+
suffix: <span>Suffix</span>,
104+
allowClear: true,
105+
classNames,
106+
styles,
107+
}),
108+
);
109+
110+
// Test prefix
111+
const prefixElement = container.querySelector(`.${classNames.prefix}`);
112+
expect(prefixElement).toBeTruthy();
113+
expect(prefixElement).toHaveStyle(styles.prefix);
114+
115+
// Test suffix
116+
const suffixElement = container.querySelector(`.${classNames.suffix}`);
117+
expect(suffixElement).toBeTruthy();
118+
expect(suffixElement).toHaveStyle(styles.suffix);
119+
120+
// Test content
121+
const contentElement = container.querySelector(`.${classNames.content}`);
122+
expect(contentElement).toBeTruthy();
123+
expect(contentElement).toHaveStyle(styles.content);
124+
125+
// Test clear
126+
const clearElement = container.querySelector(`.${classNames.clear}`);
127+
expect(clearElement).toBeTruthy();
128+
expect(clearElement).toHaveStyle(styles.clear);
129+
130+
// Test items (multiple mode specific)
131+
const items = container.querySelectorAll(`.${classNames.item}`);
132+
expect(items.length).toBeGreaterThan(0);
133+
items.forEach(item => {
134+
expect(item).toHaveStyle(styles.item);
135+
});
136+
137+
// Test item contents (multiple mode specific)
138+
const itemContents = container.querySelectorAll(`.${classNames.itemContent}`);
139+
expect(itemContents.length).toBeGreaterThan(0);
140+
itemContents.forEach(content => {
141+
expect(content).toHaveStyle(styles.itemContent);
142+
});
143+
144+
// Test item remove buttons (multiple mode specific)
145+
const removeButtons = container.querySelectorAll(`.${classNames.itemRemove}`);
146+
expect(removeButtons.length).toBeGreaterThan(0);
147+
removeButtons.forEach(button => {
148+
expect(button).toHaveStyle(styles.itemRemove);
149+
});
150+
});
151+
});

0 commit comments

Comments
 (0)