Skip to content

Commit c9ee6b9

Browse files
committed
fix: components should work
1 parent 49bcee8 commit c9ee6b9

File tree

6 files changed

+68
-1
lines changed

6 files changed

+68
-1
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
'default-case': 0,
1313
'no-confusing-arrow': 0,
1414
'jsx-a11y/no-autofocus': 0,
15+
'jsx-a11y/heading-has-content': 0,
1516
'import/no-extraneous-dependencies': [
1617
'error',
1718
{ devDependencies: ['**/tests/**'] },

examples/range.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ export default () => {
7474
console.log('OK!!!', dates);
7575
}}
7676
/>
77+
<RangePicker<Moment>
78+
{...sharedProps}
79+
value={undefined}
80+
locale={zhCN}
81+
allowClear
82+
picker="time"
83+
ranges={{
84+
test: [moment(), moment().add(1, 'hour')],
85+
}}
86+
/>
7787
</div>
7888

7989
<div style={{ margin: '0 8px' }}>

src/Picker.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
161161
onClick,
162162
onSelect,
163163
onOk,
164+
components,
164165
} = props as MergedPickerProps<DateType>;
165166

166167
const inputRef = React.useRef<HTMLInputElement>(null);
@@ -363,6 +364,7 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
363364

364365
const rangesNode = getRanges({
365366
prefixCls,
367+
components,
366368
needConfirmButton,
367369
okDisabled: !selectedValue,
368370
locale,

src/PickerPanel.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ function PickerPanel<DateType>(props: PickerPanelProps<DateType>) {
142142
onMouseDown,
143143
onPickerValueChange,
144144
onOk,
145+
components,
145146
} = props as MergedPickerPanelProps<DateType>;
146147

147148
const needConfirmButton: boolean =
@@ -422,6 +423,7 @@ function PickerPanel<DateType>(props: PickerPanelProps<DateType>) {
422423
extraFooter = getExtraFooter(prefixCls, mergedMode, renderExtraFooter);
423424
rangesNode = getRanges({
424425
prefixCls,
426+
components,
425427
needConfirmButton,
426428
okDisabled: !mergedValue,
427429
locale,

src/RangePicker.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
202202
onFocus,
203203
onBlur,
204204
onOk,
205+
components,
205206
} = props as MergedRangePickerProps<DateType>;
206207

207208
const needConfirmButton: boolean =
@@ -764,6 +765,7 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
764765

765766
const rangesNode = getRanges({
766767
prefixCls,
768+
components,
767769
needConfirmButton,
768770
okDisabled: !getValue(selectedValue, activePickerIndex),
769771
locale,
@@ -819,7 +821,7 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
819821
}}
820822
>
821823
<div className={`${prefixCls}-panels`}>{panels}</div>
822-
<div className={`${prefixCls}-picker-footer`}>
824+
<div className={`${prefixCls}-footer`}>
823825
{extraNode}
824826
{rangesNode}
825827
</div>

tests/components.spec.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react';
2+
import MockDate from 'mockdate';
3+
import {
4+
mount,
5+
getMoment,
6+
MomentRangePicker,
7+
MomentPicker,
8+
MomentPickerPanel,
9+
} from './util/commonUtil';
10+
11+
describe('Picker.Components', () => {
12+
beforeAll(() => {
13+
MockDate.set(getMoment('1990-09-03 00:00:00').toDate());
14+
});
15+
16+
afterAll(() => {
17+
MockDate.reset();
18+
});
19+
20+
[
21+
{ name: 'RangePicker', component: MomentRangePicker, ranges: true },
22+
{ name: 'Picker', component: MomentPicker },
23+
{ name: 'PickerPanel', component: MomentPickerPanel },
24+
].forEach(({ name, component, ranges }) => {
25+
it(name, () => {
26+
const Component = component as any;
27+
const Button: React.FC<any> = props => <h1 {...props} />;
28+
const Item: React.FC<any> = props => <h2 {...props} />;
29+
30+
const wrapper = mount(
31+
<Component
32+
ranges={{
33+
good: [null, null],
34+
}}
35+
components={{
36+
button: Button,
37+
rangeItem: Item,
38+
}}
39+
picker="time"
40+
open
41+
/>,
42+
);
43+
44+
expect(wrapper.find('.rc-picker-footer').find('h1')).toHaveLength(1);
45+
if (ranges) {
46+
expect(wrapper.find('.rc-picker-footer').find('h2')).toHaveLength(1);
47+
}
48+
});
49+
});
50+
});

0 commit comments

Comments
 (0)