Skip to content

Commit 48d51c5

Browse files
committed
save
1 parent 459a57a commit 48d51c5

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/TreeSelectContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ExpandAction } from '@rc-component/tree/lib/Tree';
33
import type { DataNode, FieldNames, Key } from './interface';
44
import type useDataEntities from './hooks/useDataEntities';
55

6-
export type SemanticName = 'itemIcon' | 'item' | 'itemTitle' | 'input' | 'prefix' | 'suffix';
6+
export type SemanticName = 'item' | 'itemTitle' | 'input' | 'prefix' | 'suffix';
77
export interface TreeSelectContextProps {
88
virtual?: boolean;
99
popupMatchSelectWidth?: boolean | number;

tests/Select.spec.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,4 +638,71 @@ describe('TreeSelect.basic', () => {
638638
const { container } = render(<TreeSelect ref={treeSelectRef} />);
639639
expect(treeSelectRef.current.nativeElement).toBe(container.querySelector('.rc-tree-select'));
640640
});
641+
642+
it('support classNames and styles', () => {
643+
const treeData = [
644+
{
645+
value: 'parent 1',
646+
title: 'parent 1',
647+
children: [
648+
{
649+
value: 'parent 1-0',
650+
title: 'parent 1-0',
651+
children: [
652+
{
653+
value: 'leaf1',
654+
title: 'my leaf',
655+
},
656+
{
657+
value: 'leaf2',
658+
title: 'your leaf',
659+
},
660+
],
661+
},
662+
],
663+
},
664+
];
665+
const customClassNames = {
666+
prefix: 'test-prefix',
667+
input: 'test-input',
668+
suffix: 'test-suffix',
669+
item: 'test-item',
670+
itemTitle: 'test-item-title',
671+
};
672+
const customStyles = {
673+
prefix: { color: 'green' },
674+
input: { color: 'blue' },
675+
suffix: { color: 'yellow' },
676+
item: { color: 'black' },
677+
itemTitle: { color: 'purple' },
678+
};
679+
const { container } = render(
680+
<TreeSelect
681+
classNames={customClassNames}
682+
styles={customStyles}
683+
showSearch
684+
prefix="Prefix"
685+
open
686+
suffixIcon={() => <div>icon</div>}
687+
placeholder="Please select"
688+
treeDefaultExpandAll
689+
treeData={treeData}
690+
/>,
691+
);
692+
const prefix = container.querySelector('.rc-tree-select-prefix');
693+
const input = container.querySelector('.rc-tree-select-selection-search-input');
694+
const suffix = container.querySelector('.rc-tree-select-arrow');
695+
const itemTitle = container.querySelector('.rc-tree-select-tree-title');
696+
const item = container.querySelector(`.${customClassNames.item}`);
697+
expect(prefix).toHaveClass(customClassNames.prefix);
698+
expect(input).toHaveClass(customClassNames.input);
699+
expect(suffix).toHaveClass(customClassNames.suffix);
700+
expect(itemTitle).toHaveClass(customClassNames.itemTitle);
701+
702+
expect(prefix).toHaveStyle(customStyles.prefix);
703+
expect(input).toHaveStyle(customStyles.input);
704+
expect(suffix).toHaveStyle(customStyles.suffix);
705+
expect(itemTitle).toHaveStyle(customStyles.itemTitle);
706+
expect(item).toHaveStyle(customStyles.item);
707+
});
641708
});

0 commit comments

Comments
 (0)