Skip to content

refactor: popup structure #1145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
direction={direction}
innerProps={virtual ? null : a11yProps}
showScrollBar={showScrollBar}
className={contextClassNames?.list}
style={contextStyles?.list}
className={contextClassNames?.popup?.list}
style={contextStyles?.popup?.list}
>
{(item, itemIndex) => {
const { group, groupOption, data, label, value } = item;
Expand Down Expand Up @@ -363,7 +363,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
itemPrefixCls,
optionPrefixCls,
className,
contextClassNames?.listItem,
contextClassNames?.popup?.listItem,
{
[`${optionPrefixCls}-grouped`]: groupOption,
[`${optionPrefixCls}-active`]: activeIndex === itemIndex && !mergedDisabled,
Expand Down Expand Up @@ -403,7 +403,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
onSelectValue(value);
}
}}
style={{ ...contextStyles?.listItem, ...style }}
style={{ ...contextStyles?.popup?.listItem, ...style }}
>
<div className={`${optionPrefixCls}-content`}>
{typeof optionRender === 'function'
Expand Down
3 changes: 2 additions & 1 deletion src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export type SelectHandler<ValueType, OptionType extends BaseOptionType = Default

type ArrayElementType<T> = T extends (infer E)[] ? E : T;

export type SemanticName = BaseSelectSemanticName | 'listItem' | 'list';
export type SemanticName = BaseSelectSemanticName;
export type PopupSemantic = 'listItem' | 'list';
export interface SelectProps<ValueType = any, OptionType extends BaseOptionType = DefaultOptionType>
extends BaseSelectPropsWithoutPrivate {
prefixCls?: string;
Expand Down
9 changes: 7 additions & 2 deletions src/SelectContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
OnInternalSelect,
SelectProps,
SemanticName,
PopupSemantic,
} from './Select';
import type { FlattenOptionData } from './interface';

Expand All @@ -15,8 +16,12 @@ import type { FlattenOptionData } from './interface';
* SelectContext is only used for Select. BaseSelect should not consume this context.
*/
export interface SelectContextProps {
classNames?: Partial<Record<SemanticName, string>>;
styles?: Partial<Record<SemanticName, React.CSSProperties>>;
classNames?: Partial<Record<SemanticName, string>> & {
popup?: Partial<Record<PopupSemantic, string>>;
};
styles?: Partial<Record<SemanticName, React.CSSProperties>> & {
popup?: Partial<Record<PopupSemantic, React.CSSProperties>>;
};
options: BaseOptionType[];
optionRender?: SelectProps['optionRender'];
flattenOptions: FlattenOptionData<BaseOptionType>[];
Expand Down
20 changes: 12 additions & 8 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2423,16 +2423,20 @@ describe('Select.Basic', () => {
const customClassNames = {
prefix: 'custom-prefix',
suffix: 'custom-suffix',
list: 'custom-list',
listItem: 'custom-item',
input: 'custom-input',
popup: {
list: 'custom-list',
listItem: 'custom-item',
},
};
const customStyle = {
prefix: { color: 'red' },
suffix: { color: 'green' },
list: { color: 'yellow' },
listItem: { color: 'blue' },
input: { color: 'black' },
popup: {
list: { color: 'yellow' },
listItem: { color: 'blue' },
},
};
const { container } = render(
<Select
Expand All @@ -2459,10 +2463,10 @@ describe('Select.Basic', () => {
expect(prefix).toHaveStyle(customStyle.prefix);
expect(suffix).toHaveClass(customClassNames.suffix);
expect(suffix).toHaveStyle(customStyle.suffix);
expect(item).toHaveClass(customClassNames.listItem);
expect(item).toHaveStyle(customStyle.listItem);
expect(list).toHaveClass(customClassNames.list);
expect(list).toHaveStyle(customStyle.list);
expect(item).toHaveClass(customClassNames.popup.listItem);
expect(item).toHaveStyle(customStyle.popup.listItem);
expect(list).toHaveClass(customClassNames.popup.list);
expect(list).toHaveStyle(customStyle.popup.list);
expect(input).toHaveClass(customClassNames.input);
expect(input).toHaveStyle(customStyle.input);
});
Expand Down
Loading