Skip to content
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
16 changes: 11 additions & 5 deletions src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export interface RefOptionListProps {
scrollTo?: (index: number) => void;
}

function isTitleType(content: any) {
return typeof content === 'string' || typeof content === 'number';
}

/**
* Using virtual list of option display.
* Will fallback to dom if use customize render.
Expand Down Expand Up @@ -272,8 +276,13 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, OptionListP

// Group
if (group) {
const groupTitle = data.title ?? (isTitleType(label) && label);

return (
<div className={classNames(itemPrefixCls, `${itemPrefixCls}-group`)}>
<div
className={classNames(itemPrefixCls, `${itemPrefixCls}-group`)}
title={groupTitle}
>
{label !== undefined ? label : key}
</div>
);
Expand Down Expand Up @@ -301,10 +310,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, OptionListP
// https://github.com/ant-design/ant-design/issues/34145
const content = typeof mergedLabel === 'number' ? mergedLabel : mergedLabel || value;
// https://github.com/ant-design/ant-design/issues/26717
let optionTitle =
typeof content === 'string' || typeof content === 'number'
? content.toString()
: undefined;
let optionTitle = isTitleType(content) ? content.toString() : undefined;
if (title !== undefined) {
optionTitle = title;
}
Expand Down
22 changes: 22 additions & 0 deletions tests/Group.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,26 @@ describe('Select.Group', () => {
wrapper.find('input').simulate('change', { target: { value: '1' } });
expect(wrapper.find('List').props().data).toHaveLength(2);
});

describe('group title', () => {
it('label as title', () => {
const wrapper = mount(
<Select open>
<OptGroup label="zombiej" />
</Select>,
);

expect(wrapper.find('.rc-select-item-group').prop('title')).toEqual('zombiej');
});

it('customize title', () => {
const wrapper = mount(
<Select open>
<OptGroup label="zombiej" title="bamboo" />
</Select>,
);

expect(wrapper.find('.rc-select-item-group').prop('title')).toEqual('bamboo');
});
});
});
2 changes: 2 additions & 0 deletions tests/__snapshots__/Select.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ exports[`Select.Basic render renders dropdown correctly 1`] = `
>
<div
class="antd-item antd-item-group"
title="manager"
>
manager
</div>
Expand Down Expand Up @@ -584,6 +585,7 @@ exports[`Select.Basic render renders dropdown correctly 1`] = `
</div>
<div
class="antd-item antd-item-group"
title="engineer"
>
engineer
</div>
Expand Down
2 changes: 2 additions & 0 deletions tests/__snapshots__/Tags.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ exports[`Select.Tags OptGroup renders correctly 1`] = `
>
<div
class="rc-select-item rc-select-item-group"
title="Manager"
>
Manager
</div>
Expand Down Expand Up @@ -170,6 +171,7 @@ exports[`Select.Tags OptGroup renders correctly 1`] = `
</div>
<div
class="rc-select-item rc-select-item-group"
title="Engineer"
>
Engineer
</div>
Expand Down