Skip to content

Commit

Permalink
feat: make placeholder fields optional for SInputYMD and SInputHMS (
Browse files Browse the repository at this point in the history
  • Loading branch information
ryo-gk committed Apr 27, 2023
1 parent 90bb10c commit cb3b998
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/components/SInputHMS.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export interface Value {
}
export interface Placeholder {
hour: string
minute: string
second: string
hour?: string
minute?: string
second?: string
}
export type ValueType = 'hour' | 'minute' | 'second'
Expand Down Expand Up @@ -63,9 +63,9 @@ const padValue = computed(() => {
const padPlaceholder = computed(() => {
return {
hour: props.placeholder?.hour.toString().padStart(2, '0') ?? '00',
minute: props.placeholder?.minute.toString().padStart(2, '0') ?? '00',
second: props.placeholder?.second.toString().padStart(2, '0') ?? '00'
hour: props.placeholder?.hour?.toString().padStart(2, '0') ?? '00',
minute: props.placeholder?.minute?.toString().padStart(2, '0') ?? '00',
second: props.placeholder?.second?.toString().padStart(2, '0') ?? '00'
}
})
Expand Down
12 changes: 6 additions & 6 deletions lib/components/SInputYMD.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export interface Value {
export type ValueType = 'year' | 'month' | 'date'
export interface Placeholder {
year: number
month: number
date: number
year?: number
month?: number
date?: number
}
const props = defineProps<{
Expand Down Expand Up @@ -64,9 +64,9 @@ const padValue = computed(() => {
const padPlaceholder = computed(() => {
return {
year: props.placeholder?.year.toString().padStart(4, '0') ?? '1998',
month: props.placeholder?.month.toString().padStart(2, '0') ?? '01',
date: props.placeholder?.date.toString().padStart(2, '0') ?? '14'
year: props.placeholder?.year?.toString().padStart(4, '0') ?? '1998',
month: props.placeholder?.month?.toString().padStart(2, '0') ?? '01',
date: props.placeholder?.date?.toString().padStart(2, '0') ?? '14'
}
})
Expand Down
13 changes: 13 additions & 0 deletions tests/components/SInputHMS.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ describe('components/SInputHMS', async () => {
expect(getInputPlaceholder(wrapper.find('.SInputHMS .input.second'))).toBe('06')
})

test('accepts `:placeholder` partially', async () => {
const wrapper = mount(SInputHMS)

await wrapper.setProps({ placeholder: { hour: 10 } })
expect(getInputPlaceholder(wrapper.find('.SInputHMS .input.hour'))).toBe('10')

await wrapper.setProps({ placeholder: { minute: 8 } })
expect(getInputPlaceholder(wrapper.find('.SInputHMS .input.minute'))).toBe('08')

await wrapper.setProps({ placeholder: { second: 6 } })
expect(getInputPlaceholder(wrapper.find('.SInputHMS .input.second'))).toBe('06')
})

test('focuses conatiner when input is focused', async () => {
const wrapper = mount(SInputHMS)

Expand Down
13 changes: 13 additions & 0 deletions tests/components/SInputYMD.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ describe('components/SInputYMD', async () => {
expect(getInputPlaceholder(wrapper.find('.SInputYMD .input.date'))).toBe('15')
})

test('accepts `:placeholder` partially', async () => {
const wrapper = mount(SInputYMD)

await wrapper.setProps({ placeholder: { year: 1985 } })
expect(getInputPlaceholder(wrapper.find('.SInputYMD .input.year'))).toBe('1985')

await wrapper.setProps({ placeholder: { month: 10 } })
expect(getInputPlaceholder(wrapper.find('.SInputYMD .input.month'))).toBe('10')

await wrapper.setProps({ placeholder: { date: 15 } })
expect(getInputPlaceholder(wrapper.find('.SInputYMD .input.date'))).toBe('15')
})

test('focuses conatiner when input is focused', async () => {
const wrapper = mount(SInputYMD)

Expand Down

0 comments on commit cb3b998

Please sign in to comment.