Skip to content

Commit

Permalink
fix: when custom formatting causes the time-panel error (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxiong10 committed Nov 21, 2019
1 parent 742c408 commit bf949af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 14 additions & 0 deletions __test__/time-panel.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mount } from '@vue/test-utils';
import TimePanel from '../src/time/time-panel';
import ListColumns from '../src/time/list-columns.vue';

let wrapper;

Expand Down Expand Up @@ -96,4 +97,17 @@ describe('TimePanel', () => {
hour.trigger('click');
expect(wrapper.emitted().select).toBeUndefined();
});

it('fix: when the custom format pass into time panel', () => {
wrapper = mount(TimePanel, {
propsData: {
value: new Date(),
format: {},
},
});
const cols = wrapper.find(ListColumns);
expect(cols.props('showHour')).toBe(true);
expect(cols.props('showMinute')).toBe(true);
expect(cols.props('showSecond')).toBe(true);
});
});
8 changes: 5 additions & 3 deletions src/time/time-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
:date="innerValue"
:get-classes="getClasses"
:options="timePickerOptions"
:format="format"
:format="innerForamt"
@select="handleSelect"
></list-options>
<list-columns
Expand Down Expand Up @@ -53,7 +53,6 @@ export default {
},
},
format: {
type: String,
default: 'HH:mm:ss',
},
timeTitleFormat: {
Expand Down Expand Up @@ -115,8 +114,11 @@ export default {
const date = new Date(this.innerValue);
return this.formatDate(date, titleFormat);
},
innerForamt() {
return typeof this.format === 'string' ? this.format : 'HH:mm:ss';
},
ShowHourMinuteSecondAMPM() {
const { format } = this;
const format = this.innerForamt;
const defaultProps = {
showHour: /[HhKk]/.test(format),
showMinute: /m/.test(format),
Expand Down

0 comments on commit bf949af

Please sign in to comment.