From 3fbf2d82897d3c7a5c92e6a5e41734b094e5c5da Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 22 Aug 2024 00:14:43 +0200 Subject: [PATCH] feat(NcDialogButton): Allow to return `false` from callback to keep dialog 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 --- l10n/messages.pot | 4 ++ src/components/NcDialog/NcDialog.vue | 63 ++++++++++++++++++- .../NcDialogButton/NcDialogButton.vue | 36 ++++++++--- 3 files changed, 94 insertions(+), 9 deletions(-) diff --git a/l10n/messages.pot b/l10n/messages.pot index 40580f46cc..fb61015786 100644 --- a/l10n/messages.pot +++ b/l10n/messages.pot @@ -194,6 +194,10 @@ msgstr "" msgid "Load more \"{options}\"" msgstr "" +#. TRANSLATORS: The button is in a loading state +msgid "Loading …" +msgstr "" + #. TRANSLATORS: A color name for RGB(45, 115, 190) msgid "Mariner" msgstr "" diff --git a/src/components/NcDialog/NcDialog.vue b/src/components/NcDialog/NcDialog.vue index a14acdb76b..971b890c26 100644 --- a/src/components/NcDialog/NcDialog.vue +++ b/src/components/NcDialog/NcDialog.vue @@ -106,7 +106,6 @@ Note that this is not possible if the dialog contains a navigation! ``` + +### Loading buttons +Sometimes a dialog ends with a request and this request might fail due to server-side-validation. +In this case it is often desired to keep the dialog open, this can be done by returning `false` from the button callback, +to not block this callback should return a `Promise`. + +While the promise is awaited the button will have a loading state, +this means, as long as no custom `icon`-slot is used, a loading icon will be shown. +Please note that the **button will not be disabled or accessibility reasons**, +because disabled elements cannot be focused and so the loading state could not be communicated e.g. via screen readers. + +```vue + + +```