Skip to content

Commit e63d96e

Browse files
authored
feat: support title (#931)
1 parent 24d4972 commit e63d96e

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

src/BaseSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export type BaseSelectPropsWithoutPrivate = Omit<BaseSelectProps, keyof BaseSele
126126
export interface BaseSelectProps extends BaseSelectPrivateProps, React.AriaAttributes {
127127
className?: string;
128128
style?: React.CSSProperties;
129+
title?: string;
129130
showSearch?: boolean;
130131
tagRender?: (props: CustomTagProps) => React.ReactElement;
131132
direction?: 'ltr' | 'rtl';
@@ -830,7 +831,6 @@ const BaseSelect = React.forwardRef((props: BaseSelectProps, ref: React.Ref<Base
830831
</span>
831832
)}
832833
{selectorNode}
833-
834834
{arrowNode}
835835
{clearNode}
836836
</div>

src/Selector/SingleSelector.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const SingleSelector: React.FC<SelectorProps> = (props) => {
3636
onInputPaste,
3737
onInputCompositionStart,
3838
onInputCompositionEnd,
39+
title,
3940
} = props;
4041

4142
const [inputChanged, setInputChanged] = React.useState(false);
@@ -58,8 +59,8 @@ const SingleSelector: React.FC<SelectorProps> = (props) => {
5859
// Not show text when closed expect combobox mode
5960
const hasTextInput = mode !== 'combobox' && !open && !showSearch ? false : !!inputValue;
6061

61-
// Get title
62-
const title = getTitle(item);
62+
// Get title of selection item
63+
const selectionTitle = title === undefined ? getTitle(item) : title;
6364

6465
const renderPlaceholder = () => {
6566
if (item) {
@@ -105,7 +106,7 @@ const SingleSelector: React.FC<SelectorProps> = (props) => {
105106

106107
{/* Display value */}
107108
{!combobox && item && !hasTextInput && (
108-
<span className={`${prefixCls}-selection-item`} title={title}>
109+
<span className={`${prefixCls}-selection-item`} title={selectionTitle}>
109110
{item.label}
110111
</span>
111112
)}

src/Selector/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface InnerSelectorProps {
2222
prefixCls: string;
2323
id: string;
2424
mode: Mode;
25+
title?: string;
2526

2627
inputRef: React.Ref<HTMLInputElement | HTMLTextAreaElement>;
2728
placeholder?: React.ReactNode;

tests/Select.test.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,4 +1974,33 @@ describe('Select.Basic', () => {
19741974
expect(wrapper.find('.rc-select').getDOMNode().className).toContain('-focused');
19751975
jest.useRealTimers();
19761976
});
1977+
1978+
it('should support title', () => {
1979+
const wrapper1 = mount(
1980+
<Select
1981+
defaultValue="lucy"
1982+
options={[]}
1983+
/>,
1984+
);
1985+
expect(wrapper1.find('.rc-select').prop('title')).toBe(undefined);
1986+
expect(wrapper1.find('.rc-select-selection-item').prop('title')).toBe('lucy');
1987+
const wrapper2 = mount(
1988+
<Select
1989+
defaultValue="lucy"
1990+
options={[]}
1991+
title=""
1992+
/>,
1993+
);
1994+
expect(wrapper2.find('.rc-select').prop('title')).toBe('');
1995+
expect(wrapper2.find('.rc-select-selection-item').prop('title')).toBe('');
1996+
const wrapper3 = mount(
1997+
<Select
1998+
defaultValue="lucy"
1999+
options={[]}
2000+
title="title"
2001+
/>,
2002+
);
2003+
expect(wrapper3.find('.rc-select').prop('title')).toBe('title');
2004+
expect(wrapper3.find('.rc-select-selection-item').prop('title')).toBe('title');
2005+
});
19772006
});

0 commit comments

Comments
 (0)