Skip to content

Commit 9cf6f17

Browse files
authored
refactor: popup object (#644)
1 parent 6fa2d68 commit 9cf6f17

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

src/OptionList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
344344
)}
345345
<UnstableContext.Provider value={{ nodeDisabled }}>
346346
<Tree
347-
classNames={treeClassNames}
348-
styles={styles}
347+
classNames={treeClassNames?.popup}
348+
styles={styles?.popup}
349349
ref={treeRef}
350350
focusable={false}
351351
prefixCls={`${prefixCls}-tree`}

src/TreeSelect.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,19 @@ import type {
3535
LegacyDataNode,
3636
} from './interface';
3737

38+
export type SemanticName = 'input' | 'prefix' | 'suffix';
39+
export type PopupSemantic = 'item' | 'itemTitle';
3840
export interface TreeSelectProps<ValueType = any, OptionType extends DataNode = DataNode>
39-
extends Omit<BaseSelectPropsWithoutPrivate, 'mode'> {
41+
extends Omit<BaseSelectPropsWithoutPrivate, 'mode' | 'classNames' | 'styles'> {
4042
prefixCls?: string;
4143
id?: string;
4244
children?: React.ReactNode;
43-
45+
styles?: Partial<Record<SemanticName, React.CSSProperties>> & {
46+
popup?: Partial<Record<PopupSemantic, React.CSSProperties>>;
47+
};
48+
classNames?: Partial<Record<SemanticName, string>> & {
49+
popup?: Partial<Record<PopupSemantic, string>>;
50+
};
4451
// >>> Value
4552
value?: ValueType;
4653
defaultValue?: ValueType;

src/TreeSelectContext.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import * as React from 'react';
22
import type { ExpandAction } from '@rc-component/tree/lib/Tree';
33
import type { DataNode, FieldNames, Key } from './interface';
44
import type useDataEntities from './hooks/useDataEntities';
5+
import { TreeSelectProps } from './TreeSelect';
56

6-
export type SemanticName = 'item' | 'itemTitle' | 'input' | 'prefix' | 'suffix';
77
export interface TreeSelectContextProps {
88
virtual?: boolean;
99
popupMatchSelectWidth?: boolean | number;
@@ -22,8 +22,8 @@ export interface TreeSelectContextProps {
2222
/** When `true`, only take leaf node as count, or take all as count with `maxCount` limitation */
2323
leafCountOnly: boolean;
2424
valueEntities: ReturnType<typeof useDataEntities>['valueEntities'];
25-
styles?: Partial<Record<SemanticName, React.CSSProperties>>;
26-
classNames?: Partial<Record<SemanticName, string>>;
25+
classNames: TreeSelectProps['classNames'];
26+
styles: TreeSelectProps['styles'];
2727
}
2828

2929
const TreeSelectContext = React.createContext<TreeSelectContextProps>(null as any);

tests/Select.spec.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -666,15 +666,19 @@ describe('TreeSelect.basic', () => {
666666
prefix: 'test-prefix',
667667
input: 'test-input',
668668
suffix: 'test-suffix',
669-
item: 'test-item',
670-
itemTitle: 'test-item-title',
669+
popup: {
670+
item: 'test-item',
671+
itemTitle: 'test-item-title',
672+
},
671673
};
672674
const customStyles = {
673675
prefix: { color: 'green' },
674676
input: { color: 'blue' },
675677
suffix: { color: 'yellow' },
676-
item: { color: 'black' },
677-
itemTitle: { color: 'purple' },
678+
popup: {
679+
item: { color: 'black' },
680+
itemTitle: { color: 'purple' },
681+
},
678682
};
679683
const { container } = render(
680684
<TreeSelect
@@ -693,16 +697,16 @@ describe('TreeSelect.basic', () => {
693697
const input = container.querySelector('.rc-tree-select-selection-search-input');
694698
const suffix = container.querySelector('.rc-tree-select-arrow');
695699
const itemTitle = container.querySelector('.rc-tree-select-tree-title');
696-
const item = container.querySelector(`.${customClassNames.item}`);
700+
const item = container.querySelector(`.${customClassNames.popup.item}`);
697701
expect(prefix).toHaveClass(customClassNames.prefix);
698702
expect(input).toHaveClass(customClassNames.input);
699703
expect(suffix).toHaveClass(customClassNames.suffix);
700-
expect(itemTitle).toHaveClass(customClassNames.itemTitle);
704+
expect(itemTitle).toHaveClass(customClassNames.popup.itemTitle);
701705

702706
expect(prefix).toHaveStyle(customStyles.prefix);
703707
expect(input).toHaveStyle(customStyles.input);
704708
expect(suffix).toHaveStyle(customStyles.suffix);
705-
expect(itemTitle).toHaveStyle(customStyles.itemTitle);
706-
expect(item).toHaveStyle(customStyles.item);
709+
expect(itemTitle).toHaveStyle(customStyles.popup.itemTitle);
710+
expect(item).toHaveStyle(customStyles.popup.item);
707711
});
708712
});

0 commit comments

Comments
 (0)