diff --git a/docs/components/modal.md b/docs/components/modal.md index e3e73d7bd1..186800e95b 100644 --- a/docs/components/modal.md +++ b/docs/components/modal.md @@ -365,7 +365,6 @@ Use this prop to make modal window take up almost the whole screen. When set to @proceed="closeAllModals" /> - ```html Modal + + + + +```html + + + +``` + +:::tip NOTE +Sometimes you may need to asynchronously fetch data before displaying the form inside a modal. In that case, you can bind `inputAutofocus` to your local loading state variable in order to set `inputAutofocus` prop to `true` as soon as content loads so that KModal could set focus on input fields as soon as they are available. + +Modal + + +
+ +
+
+ +```vue + + + +``` +::: + ## Slots ### default Slot for modal content. Not to be confused with the [`content`](#content) slot which takes presense over all other slots when provided. -Modal +Modal @@ -452,10 +547,10 @@ Slot for modal content. Not to be confused with the [`content`](#content) slot w Slot for title string. -Modal +Modal @@ -481,10 +576,10 @@ Slot for title string. Slot for footer content. -Modal +Modal @@ -510,10 +605,10 @@ Slot for footer content. Use this slot should you need to provide cusom buttons in modal footer. Ommited when [`footer` slot](#footer) is used. -Modal +Modal @@ -573,10 +668,10 @@ By default KModal provides you with the standard layout: modal header (optional) Focus-trap requires at least one tabbable element to be present in modal at all times. You can learn more about what elements are considered tabbable [here](https://github.com/focus-trap/tabbable). Make sure your modal has at least one element with non-negative `tabindex` attribute (for example close icon with `role="button"` and `tabindex="0"` attributes). ::: -Modal +Modal
- + diff --git a/src/components/KModal/KModal.cy.ts b/src/components/KModal/KModal.cy.ts index 6c4c972651..b3e10e84d8 100644 --- a/src/components/KModal/KModal.cy.ts +++ b/src/components/KModal/KModal.cy.ts @@ -272,4 +272,18 @@ describe('KModal', () => { cy.wrap(Cypress.vueWrapper.emitted()).should('have.property', 'cancel').and('have.length', 1) }) }) + + it('sets focus on first input field when inputAutofocus is true', () => { + mount(KModal, { + props: { + visible: true, + inputAutofocus: true, + }, + slots: { + default: '', + }, + }) + + cy.get('.k-modal input[data-testid="slotted-input"]').should('have.focus') + }) }) diff --git a/src/components/KModal/KModal.vue b/src/components/KModal/KModal.vue index a9514a5325..6582b575e3 100644 --- a/src/components/KModal/KModal.vue +++ b/src/components/KModal/KModal.vue @@ -23,6 +23,7 @@