From 28860a17bb5024ec2edd2d8b1f9f24ff03b891dc 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. Co-authored-by: Ferdinand Thiessen Co-authored-by: Grigorii K. Shartsev Signed-off-by: Ferdinand Thiessen --- l10n/messages.pot | 4 + src/components/NcDialog/NcDialog.vue | 93 +++++++++- .../NcDialogButton/NcDialogButton.vue | 169 ++++++++++-------- styleguide.config.cjs | 3 + 4 files changed, 184 insertions(+), 85 deletions(-) diff --git a/l10n/messages.pot b/l10n/messages.pot index 9e1c2b52e6..da0ef21167 100644 --- a/l10n/messages.pot +++ b/l10n/messages.pot @@ -191,6 +191,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 53bc6d6c86..c129748fd7 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`. + +It is also possible to get the result of the callback from the dialog, as the result is passed as the payload of the `closing` event. + +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 + + +``` - diff --git a/styleguide.config.cjs b/styleguide.config.cjs index 981e528fb1..73e94f1550 100644 --- a/styleguide.config.cjs +++ b/styleguide.config.cjs @@ -66,6 +66,9 @@ module.exports = async () => { }, enhancePreviewApp: path.resolve(__dirname, 'styleguide/preview.js'), + compilerConfig: { + transforms: { asyncAwait: false }, + }, sections: [ {