Skip to content

Commit bf949af

Browse files
committed
fix: when custom formatting causes the time-panel error (#377)
1 parent 742c408 commit bf949af

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

__test__/time-panel.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mount } from '@vue/test-utils';
22
import TimePanel from '../src/time/time-panel';
3+
import ListColumns from '../src/time/list-columns.vue';
34

45
let wrapper;
56

@@ -96,4 +97,17 @@ describe('TimePanel', () => {
9697
hour.trigger('click');
9798
expect(wrapper.emitted().select).toBeUndefined();
9899
});
100+
101+
it('fix: when the custom format pass into time panel', () => {
102+
wrapper = mount(TimePanel, {
103+
propsData: {
104+
value: new Date(),
105+
format: {},
106+
},
107+
});
108+
const cols = wrapper.find(ListColumns);
109+
expect(cols.props('showHour')).toBe(true);
110+
expect(cols.props('showMinute')).toBe(true);
111+
expect(cols.props('showSecond')).toBe(true);
112+
});
99113
});

src/time/time-panel.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
:date="innerValue"
1212
:get-classes="getClasses"
1313
:options="timePickerOptions"
14-
:format="format"
14+
:format="innerForamt"
1515
@select="handleSelect"
1616
></list-options>
1717
<list-columns
@@ -53,7 +53,6 @@ export default {
5353
},
5454
},
5555
format: {
56-
type: String,
5756
default: 'HH:mm:ss',
5857
},
5958
timeTitleFormat: {
@@ -115,8 +114,11 @@ export default {
115114
const date = new Date(this.innerValue);
116115
return this.formatDate(date, titleFormat);
117116
},
117+
innerForamt() {
118+
return typeof this.format === 'string' ? this.format : 'HH:mm:ss';
119+
},
118120
ShowHourMinuteSecondAMPM() {
119-
const { format } = this;
121+
const format = this.innerForamt;
120122
const defaultProps = {
121123
showHour: /[HhKk]/.test(format),
122124
showMinute: /m/.test(format),

0 commit comments

Comments
 (0)