Skip to content

Commit

Permalink
feat(NcDialogButton): Allow to return false from callback to keep d…
Browse files Browse the repository at this point in the history
…ialog open

If the callback returns `false` then the click event will not be forwarded.
This could be usful if the click triggers a validation that fails and the user
should be able to fix the issue.

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Aug 21, 2024
1 parent f84ff80 commit 7a21af8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/components/NcDialogButton/NcDialogButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ export default defineComponent({
props: {
/**
* The function that will be called when the button is pressed
* @type {() => void}
* The function that will be called when the button is pressed.
* If the function returns `false` the click is ignored and the dialog will not be closed.
* @type {() => void|false}
*/
callback: {
type: Function,
Expand Down Expand Up @@ -103,9 +104,10 @@ export default defineComponent({
* Handle clicking the button
* @param {MouseEvent} e The click event
*/
const handleClick = (e) => {
props.callback?.()
emit('click', e)
const handleClick = async (e) => {
if (props.callback?.() !== false) {
emit('click', e)
}
}
return { handleClick }
Expand Down

0 comments on commit 7a21af8

Please sign in to comment.