mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
feat(modal) support alertdialog aria role
This commit is contained in:
parent
9202a3e0e4
commit
5dc57a0b00
2 changed files with 20 additions and 0 deletions
|
@ -16,6 +16,7 @@ export const Default = () => ({
|
||||||
open: boolean("Open (open)", true),
|
open: boolean("Open (open)", true),
|
||||||
passiveModal: boolean("Without footer (passiveModal)", false),
|
passiveModal: boolean("Without footer (passiveModal)", false),
|
||||||
danger: boolean("Danger mode (danger)", false),
|
danger: boolean("Danger mode (danger)", false),
|
||||||
|
alert: boolean('Alert mode (alert)', false),
|
||||||
shouldSubmitOnEnter: boolean(
|
shouldSubmitOnEnter: boolean(
|
||||||
"Enter key to submit (shouldSubmitOnEnter)",
|
"Enter key to submit (shouldSubmitOnEnter)",
|
||||||
false
|
false
|
||||||
|
|
|
@ -17,6 +17,12 @@
|
||||||
*/
|
*/
|
||||||
export let danger = false;
|
export let danger = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to enable alert mode
|
||||||
|
* @type {boolean} [alert=false]
|
||||||
|
*/
|
||||||
|
export let alert = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set to `true` to use the passive variant
|
* Set to `true` to use the passive variant
|
||||||
* @type {boolean} [passiveModal=false]
|
* @type {boolean} [passiveModal=false]
|
||||||
|
@ -147,8 +153,19 @@
|
||||||
|
|
||||||
$: modalLabelId = `bx--modal-header__label--modal-${id}`;
|
$: modalLabelId = `bx--modal-header__label--modal-${id}`;
|
||||||
$: modalHeadingId = `bx--modal-header__heading--modal-${id}`;
|
$: modalHeadingId = `bx--modal-header__heading--modal-${id}`;
|
||||||
|
$: modalBodyId = `bx--modal-body--${id}`;
|
||||||
$: ariaLabel =
|
$: ariaLabel =
|
||||||
modalLabel || $$props["aria-label"] || modalAriaLabel || modalHeading;
|
modalLabel || $$props["aria-label"] || modalAriaLabel || modalHeading;
|
||||||
|
|
||||||
|
let alertDialogProps = {};
|
||||||
|
$: if (alert) {
|
||||||
|
if (passiveModal) {
|
||||||
|
alertDialogProps.role = "alert";
|
||||||
|
} else if (!passiveModal) {
|
||||||
|
alertDialogProps.role = "alertdialog";
|
||||||
|
alertDialogProps["aria-describedby"] = modalBodyId;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
@ -182,6 +199,7 @@
|
||||||
<div
|
<div
|
||||||
bind:this="{innerModal}"
|
bind:this="{innerModal}"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
|
{...alertDialogProps}
|
||||||
aria-modal="true"
|
aria-modal="true"
|
||||||
aria-label="{ariaLabel}"
|
aria-label="{ariaLabel}"
|
||||||
class:bx--modal-container="{true}"
|
class:bx--modal-container="{true}"
|
||||||
|
@ -230,6 +248,7 @@
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
id="{modalBodyId}"
|
||||||
class:bx--modal-content="{true}"
|
class:bx--modal-content="{true}"
|
||||||
class:bx--modal-content--with-form="{hasForm}"
|
class:bx--modal-content--with-form="{hasForm}"
|
||||||
class:bx--modal-scroll-content="{hasScrollingContent}"
|
class:bx--modal-scroll-content="{hasScrollingContent}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue