From 2cf215e3c43cc5cf02b28791f0f2cb454b22bbf2 Mon Sep 17 00:00:00 2001 From: Alan Wang Date: Wed, 12 Jan 2022 11:11:43 +0800 Subject: [PATCH] feat(components): [el-time-select] support custom format (e.g. 12-hour) (#5309) --- docs/en-US/component/time-select.md | 55 ++++++++++++------ docs/examples/time-select/time-formats.vue | 17 ++++++ docs/examples/time-select/time-range.vue | 1 + .../time-select/__tests__/time-select.spec.ts | 22 ++++++++ .../time-select/src/time-select.vue | 56 +++++++++++++++---- 5 files changed, 124 insertions(+), 27 deletions(-) create mode 100644 docs/examples/time-select/time-formats.vue diff --git a/docs/en-US/component/time-select.md b/docs/en-US/component/time-select.md index deb637fc52..4e9cad8a19 100644 --- a/docs/en-US/component/time-select.md +++ b/docs/en-US/component/time-select.md @@ -7,6 +7,8 @@ lang: en-US Use Time Select for time input. +The available time range is 00:00 to 23:59 + ## Fixed time picker Provide a list of fixed time for users to choose. @@ -17,9 +19,27 @@ time-select/basic ::: +## Time Formats + +Use `format` to control format of time(hours and minutes). + +Check the list [here](https://day.js.org/docs/en/display/format#list-of-all-available-formats) of all available formats of Day.js. + +:::warning + +Pay attention to capitalization + +::: + +:::demo + +time-select/time-formats + +::: + ## Fixed time range -If start time is picked at first, then the end time will change accordingly. +If start( end ) time is picked at first, then the status of end( start ) time's options will change accordingly. :::demo @@ -29,22 +49,23 @@ time-select/time-range ## Attributes -| Attribute | Description | Type | Accepted Values | Default | -| --------------------- | -------------------------------------------------------- | ------------------ | ----------------------- | ----------- | -| model-value / v-model | binding value | string | — | — | -| disabled | whether TimeSelect is disabled | boolean | — | false | -| editable | whether the input is editable | boolean | — | true | -| clearable | whether to show clear button | boolean | — | true | -| size | size of Input | string | large / default / small | default | -| placeholder | placeholder in non-range mode | string | — | — | -| name | same as `name` in native input | string | — | — | -| prefix-icon | Custom prefix icon component | string / Component | — | Clock | -| clear-icon | Custom clear icon component | string / Component | — | CircleClose | -| start | start time | string | — | 09:00 | -| end | end time | string | — | 18:00 | -| step | time step | string | — | 00:30 | -| min-time | minimum time, any time before this time will be disabled | string | — | 00:00 | -| max-time | maximum time, any time after this time will be disabled | string | — | — | +| Attribute | Description | Type | Accepted Values | Default | +| --------------------- | -------------------------------------------------------- | ------------------ | -------------------------------------------------------------------------------------- | ----------- | +| model-value / v-model | binding value | string | — | — | +| disabled | whether TimeSelect is disabled | boolean | — | false | +| editable | whether the input is editable | boolean | — | true | +| clearable | whether to show clear button | boolean | — | true | +| size | size of Input | string | large / default / small | default | +| placeholder | placeholder in non-range mode | string | — | — | +| name | same as `name` in native input | string | — | — | +| prefix-icon | Custom prefix icon component | string / Component | — | Clock | +| clear-icon | Custom clear icon component | string / Component | — | CircleClose | +| start | start time | string | — | 09:00 | +| end | end time | string | — | 18:00 | +| step | time step | string | — | 00:30 | +| min-time | minimum time, any time before this time will be disabled | string | — | 00:00 | +| max-time | maximum time, any time after this time will be disabled | string | — | — | +| format | set format of time | string | see [formats](https://day.js.org/docs/en/display/format#list-of-all-available-formats) | HH:mm | ## Events diff --git a/docs/examples/time-select/time-formats.vue b/docs/examples/time-select/time-formats.vue new file mode 100644 index 0000000000..fd63699023 --- /dev/null +++ b/docs/examples/time-select/time-formats.vue @@ -0,0 +1,17 @@ + + + diff --git a/docs/examples/time-select/time-range.vue b/docs/examples/time-select/time-range.vue index 5d91483979..ff0111d143 100644 --- a/docs/examples/time-select/time-range.vue +++ b/docs/examples/time-select/time-range.vue @@ -2,6 +2,7 @@
{ const attr = popperEl.getAttribute('aria-hidden') expect(attr).toEqual('true') }) + + it('set format', async () => { + const wrapper = _mount( + ` + `, + () => ({ value: '' }) + ) + const input = wrapper.find('.el-input__inner') + await input.trigger('click') + await nextTick() + const option = document.querySelector('.el-select-dropdown__item') + expect(option.textContent).toBe('01:00 PM') + }) }) diff --git a/packages/components/time-select/src/time-select.vue b/packages/components/time-select/src/time-select.vue index 07c2b17639..916fd9a8df 100644 --- a/packages/components/time-select/src/time-select.vue +++ b/packages/components/time-select/src/time-select.vue @@ -31,12 +31,15 @@