Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NcDialog): Allow to catch reset event #6006

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions src/components/NcDialog/NcDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
name="Choose a name"
:open.sync="showDialog"
@submit="currentName = newName"
@reset="newName = ''"
@closing="newName = ''">
<NcTextField label="New name"
placeholder="Min. 6 characters"
Expand All @@ -114,8 +115,14 @@
return {
showDialog: false,
newName: '',
currentName: 'none yet.',
currentName: 'non yet.',
buttons: [
{
label: 'Reset',
nativeType: 'reset',
// returning `false` to prevent the dialog from closing
callback: () => false,
},
{
label: 'Submit',
type: 'primary',
Expand Down Expand Up @@ -169,7 +176,7 @@
<NcDialogButton v-for="(button, idx) in buttons"
:key="idx"
v-bind="button"
@click="handleButtonClose" />
@click="handleButtonClose(button)" />
</slot>
</div>
</component>
Expand Down Expand Up @@ -300,7 +307,7 @@
},

/**
* Optionally pass additionaly classes which will be set on the navigation for custom styling
* Optionally pass additional classes which will be set on the navigation for custom styling
* @default ''
* @example
* ```html
Expand Down Expand Up @@ -344,7 +351,7 @@
},

/**
* Optionally pass additionaly classes which will be set on the content wrapper for custom styling
* Optionally pass additional classes which will be set on the content wrapper for custom styling
* @default ''
*/
contentClasses: {
Expand All @@ -354,7 +361,7 @@
},

/**
* Optionally pass additionaly classes which will be set on the dialog itself
* Optionally pass additional classes which will be set on the dialog itself
* (the default `class` attribute will be set on the modal wrapper)
* @default ''
*/
Expand Down Expand Up @@ -434,6 +441,16 @@
/** Forwarded HTMLFormElement submit event (only if `is-form` is set) */
emit('submit', event)
},
/**
* @param {Event} event Form submit event
*/
reset(event) {
event.preventDefault()
/**
* Forwarded HTMLFormElement reset event (only if `is-form` is set).
*/
emit('reset', event)
}

Check warning on line 453 in src/components/NcDialog/NcDialog.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Missing trailing comma
}
: {},
)
Expand All @@ -444,12 +461,14 @@
const showModal = ref(true)

// Because NcModal does not emit `close` when show prop is changed
/**

Check warning on line 464 in src/components/NcDialog/NcDialog.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @param "button" declaration
* Handle clicking a dialog button -> should close
*/
const handleButtonClose = () => {
// Skip close if invalid dialog
if (dialogTagName.value === 'form' && !dialogElement.value.reportValidity()) {
const handleButtonClose = (button) => {
// Skip close on submit if invalid dialog
if (button.nativeType === 'submit'
&& dialogTagName.value === 'form'
&& !dialogElement.value.reportValidity()) {
return
}
handleClosing()
Expand Down
Loading