Skip to content

Commit 9d23a2f

Browse files
authored
feat: multiple single picker show placeholder (#798)
* feat: add multiple placeholder * test: add test case
1 parent 1bbc3e3 commit 9d23a2f

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

assets/index.less

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@
109109
border: none;
110110
outline: none;
111111
cursor: pointer;
112-
transition: background 0.3s, border 0.3s;
112+
transition:
113+
background 0.3s,
114+
border 0.3s;
113115

114116
&:hover {
115117
background: fade(blue, 30%);
@@ -547,6 +549,7 @@
547549
box-sizing: border-box;
548550
width: 100%;
549551
border: 1px solid green;
552+
min-height: 1em;
550553

551554
&-item {
552555
flex: none;
@@ -558,6 +561,13 @@
558561
border: 1px solid blue;
559562
}
560563

564+
&-selection-placeholder {
565+
pointer-events: none;
566+
position: absolute;
567+
left: 0;
568+
top: 0;
569+
}
570+
561571
&-multiple-input {
562572
width: 10px;
563573
opacity: 0.1;

docs/examples/debug.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'dayjs/locale/zh-cn';
1111
import buddhistEra from 'dayjs/plugin/buddhistEra';
1212
import LocalizedFormat from 'dayjs/plugin/localizedFormat';
1313
import dayjsGenerateConfig from '../../src/generate/dayjs';
14+
import dateFnsGenerateConfig from '../../src/generate/dateFns';
1415
import zhCN from '../../src/locale/zh_CN';
1516

1617
dayjs.locale('zh-cn');
@@ -36,19 +37,18 @@ const sharedLocale = {
3637
generateConfig: dayjsGenerateConfig,
3738
};
3839

40+
const dateFnsSharedLocale = {
41+
locale: myLocale,
42+
generateConfig: dateFnsGenerateConfig,
43+
};
44+
3945
export default () => {
4046
return (
4147
<div>
4248
{/* <RangePicker {...sharedLocale} style={{ width: 400 }} showTime />
4349
<RangePicker {...sharedLocale} style={{ width: 400 }} showTime showMinute={false} /> */}
44-
<SinglePicker
45-
{...sharedLocale}
46-
style={{ width: 400 }}
47-
showTime
48-
showHour
49-
showMinute
50-
// showSecond={false}
51-
/>
50+
<SinglePicker {...dateFnsSharedLocale} style={{ width: 400 }} multiple placeholder="good" />
51+
<SinglePicker {...dateFnsSharedLocale} style={{ width: 400 }} placeholder="good" />
5252
</div>
5353
);
5454
};

src/PickerInput/Selector/SingleSelector/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ function SingleSelector<DateType extends object = any>(
171171
disabled={disabled}
172172
removeIcon={removeIcon}
173173
/>
174+
{!value.length && <span className={`${prefixCls}-selection-placeholder`}>{placeholder}</span>}
174175
<input
175176
className={`${prefixCls}-multiple-input`}
176177
value={value.map(getText).join(',')}

tests/multiple.spec.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,22 @@ describe('Picker.Multiple', () => {
137137

138138
expect(container.querySelector('.custom-remove')).toBeTruthy();
139139
});
140+
141+
describe('placeholder', () => {
142+
it('show placeholder', () => {
143+
const { container } = render(<DayPicker multiple placeholder="bamboo" />);
144+
expect(
145+
container.querySelector<HTMLSpanElement>('.rc-picker-selection-placeholder').textContent,
146+
).toBe('bamboo');
147+
});
148+
149+
it('hide if has value', () => {
150+
const { container } = render(
151+
<DayPicker multiple defaultValue={[getDay('2000-01-01')]} placeholder="bamboo" />,
152+
);
153+
expect(
154+
container.querySelector<HTMLSpanElement>('.rc-picker-selection-placeholder'),
155+
).toBeFalsy();
156+
});
157+
});
140158
});

0 commit comments

Comments
 (0)