From 3fce8ac4a2ad8dbe85e55fdb3dc28c66707d43fc Mon Sep 17 00:00:00 2001 From: Limon Monte <6059356+limonte@users.noreply.github.com> Date: Sat, 28 Oct 2023 20:25:03 +0300 Subject: [PATCH] feat: support input date, datetime-local, time, week, month, search (#2679) --- cypress/e2e/inputs.cy.js | 2 +- src/utils/dom/renderers/renderInput.js | 10 +++++++--- sweetalert2.d.ts | 11 +++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cypress/e2e/inputs.cy.js b/cypress/e2e/inputs.cy.js index 60fac6326..df6466d50 100644 --- a/cypress/e2e/inputs.cy.js +++ b/cypress/e2e/inputs.cy.js @@ -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"' ) }) diff --git a/src/utils/dom/renderers/renderInput.js b/src/utils/dom/renderers/renderInput.js index 0ee655f1a..8a5c96327 100644 --- a/src/utils/dom/renderers/renderInput.js +++ b/src/utils/dom/renderers/renderInput.js @@ -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 } @@ -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) diff --git a/sweetalert2.d.ts b/sweetalert2.d.ts index 45fe0508a..0d8e779d1 100644 --- a/sweetalert2.d.ts +++ b/sweetalert2.d.ts @@ -366,6 +366,7 @@ declare module 'sweetalert2' { | 'password' | 'number' | 'tel' + | 'search' | 'range' | 'textarea' | 'select' @@ -373,6 +374,11 @@ declare module 'sweetalert2' { | 'checkbox' | 'file' | 'url' + | 'date' + | 'datetime-local' + | 'time' + | 'week' + | 'month' export type SweetAlertPosition = | 'top' @@ -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 */