Skip to content

feat(b-modal): add optional trigger parameter to $bvModal.hide() method #6523

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

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
53 changes: 42 additions & 11 deletions src/components/modal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ several methods, of which two are for showing and hiding modals:
| Method | Description |
| ------------------------ | -------------------------------------- |
| `this.$bvModal.show(id)` | Show the modal with the specified `id` |
| `this.$bvModal.hide(id)` | Hide the modal with the specified `id` |
| `this.$bvModal.hide(id, trigger = "event")` | Hide the modal with the specified `id`, and optionally supply a `trigger` like `ok`. Which will cause the modal to close as if the `OK` button was clicked |

Both methods return immediately after being called.

Expand Down Expand Up @@ -958,39 +958,70 @@ method to generate VNodes.
<template>
<div>
<b-button @click="showMsgOk">Show OK message box with custom content</b-button>
Return value: {{ returnValue }}
</div>
</template>

<script>
export default {
data() {
return {
returnValue: ''
}
},
methods: {
showMsgOk() {
async showMsgOk() {
const h = this.$createElement
const modalId = "my-confirm-modal";
// Using HTML string
const titleVNode = h('div', { domProps: { innerHTML: 'Title from <i>HTML<i> string' } })
// More complex structure
const messageVNode = h('div', { class: ['foobar'] }, [
h('p', { class: ['text-center'] }, [
h('p', { staticClass: 'text-center' }, [
' Flashy ',
h('strong', 'msgBoxOk'),
' message ',
]),
h('p', { class: ['text-center'] }, [h('b-spinner')]),
h('p', { staticClass: 'text-center' }, [h('b-spinner')]),
h('b-img', {
props: {
src: 'https://picsum.photos/id/20/250/250',
thumbnail: true,
center: true,
fluid: true, rounded: 'circle'
}
})
}),
// You can use `$bvModal.hide` to hide the modal along with an optional trigger to create custom `ok` or `cancel`.
h('p', { staticClass: 'd-flex justify-content-around mt-2' }, [
h('b-button', {
props: { variant: 'danger' },
on: {
click: () => {
this.$bvModal.hide(modalId, 'cancel')
}
}
}, 'Custom \'CANCEL\' button'),
h('b-button', {
props: { variant: 'primary' },
on: {
click: () => {
this.$bvModal.hide(modalId, 'ok')
}
}
}, 'Custom \'OK\' button')
])
])
// We must pass the generated VNodes as arrays
this.$bvModal.msgBoxOk([messageVNode], {
title: [titleVNode],
buttonSize: 'sm',
centered: true, size: 'sm'
})
try {
this.returnValue = await this.$bvModal.msgBoxConfirm([messageVNode], {
id: modalId,
title: [titleVNode],
buttonSize: 'sm',
centered: true
})
} catch(err) {
// An error occurred
}
}
}
}
Expand Down Expand Up @@ -1190,4 +1221,4 @@ Notes on `v-b-modal` directive accessibility:
then a `tabindex` of `0` will be added to the element to ensure accessibility, unless there is
already a `tabindex` set.

<!-- Component reference added automatically from component package.json -->
<!-- Component reference added automatically from component package.json -->
2 changes: 1 addition & 1 deletion src/components/modal/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export interface BvModal {
show: (id: string) => void

// Hide a modal by id
hide: (id: string) => void
hide: (id: string, trigger?: string) => void
}

// --- Vue prototype injections ---
Expand Down
4 changes: 2 additions & 2 deletions src/components/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,9 @@ export const BModal = /*#__PURE__*/ Vue.extend({
this.show()
}
},
hideHandler(id) {
hideHandler(id, trigger = 'event') {
if (id === this.modalId) {
this.hide('event')
this.hide(trigger)
}
},
toggleHandler(id, triggerEl) {
Expand Down
5 changes: 5 additions & 0 deletions src/components/modal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@
"arg": "modalId",
"type": "String",
"description": "ID of modal to hide"
},
{
"arg": "trigger",
"type": "String",
"description": "Specify which trigger the modal should use when hidden, like `ok`, `cancel` or event a custom trigger (optional)"
}
]
},
Expand Down