Skip to content

Commit

Permalink
feat: support input date, datetime-local, time, week, month, search (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
limonte committed Oct 28, 2023
1 parent f157867 commit 3fce8ac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/inputs.cy.js
Expand Up @@ -9,7 +9,7 @@ describe('Inputs', () => {
const spy = cy.spy(console, 'error')
Swal.fire({ input: 'invalid-input-type' })
expect(spy).to.be.calledWith(
'SweetAlert2: Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "invalid-input-type"'
'SweetAlert2: Unexpected type of input! Expected month | week | time | datetime-local | date | search | url | tel | number | password | email | text | file | range | select | radio | checkbox | textarea, got "invalid-input-type"'
)
})

Expand Down
10 changes: 7 additions & 3 deletions src/utils/dom/renderers/renderInput.js
Expand Up @@ -60,9 +60,7 @@ const showInput = (params) => {
}

if (!renderInputType[params.input]) {
error(
`Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "${params.input}"`
)
error(`Unexpected type of input! Expected ${Object.keys(renderInputType).join(' | ')}, got "${params.input}"`)
return
}

Expand Down Expand Up @@ -180,6 +178,12 @@ renderInputType.text =
renderInputType.number =
renderInputType.tel =
renderInputType.url =
renderInputType.search =
renderInputType.date =
renderInputType['datetime-local'] =
renderInputType.time =
renderInputType.week =
renderInputType.month =
(input, params) => {
checkAndSetInputValue(input, params.inputValue)
setInputLabel(input, input, params)
Expand Down
11 changes: 9 additions & 2 deletions sweetalert2.d.ts
Expand Up @@ -366,13 +366,19 @@ declare module 'sweetalert2' {
| 'password'
| 'number'
| 'tel'
| 'search'
| 'range'
| 'textarea'
| 'select'
| 'radio'
| 'checkbox'
| 'file'
| 'url'
| 'date'
| 'datetime-local'
| 'time'
| 'week'
| 'month'

export type SweetAlertPosition =
| 'top'
Expand Down Expand Up @@ -606,8 +612,9 @@ declare module 'sweetalert2' {
target?: string | HTMLElement | null

/**
* Input field type, can be `'text'`, `'email'`, `'password'`, `'number'`, `'tel'`, `'range'`, `'textarea'`,
* `'select'`, `'radio'`, `'checkbox'`, `'file'` and `'url'`.
* Input field type, can be `'text'`, `'email'`, `'password'`, `'number'`, `'tel'`, `'search'`, `'range'`,
* `'textarea'`, `'select'`, `'radio'`, `'checkbox'`, `'file'`, `'url'`, `'date'`, `'datetime-local'`,
* `'time'`, `'week'`, `'month'`.
*
* @default undefined
*/
Expand Down

0 comments on commit 3fce8ac

Please sign in to comment.