fix(composed-modal): add aria-label prop, update header semantic tags

This commit is contained in:
Eric Liu 2021-02-03 16:27:03 -08:00
commit baea933854
3 changed files with 16 additions and 6 deletions

View file

@ -11,7 +11,7 @@
</script> </script>
<ComposedModal open> <ComposedModal open>
<ModalHeader title="Confirm changes" /> <ModalHeader label="Changes" title="Confirm changes" />
<ModalBody hasForm> <ModalBody hasForm>
<Checkbox labelText="I have reviewed the changes" bind:checked /> <Checkbox labelText="I have reviewed the changes" bind:checked />
</ModalBody> </ModalBody>

View file

@ -38,8 +38,10 @@
afterUpdate, afterUpdate,
onDestroy, onDestroy,
} from "svelte"; } from "svelte";
import { writable } from "svelte/store";
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
const label = writable(undefined);
let buttonRef = null; let buttonRef = null;
let innerModal = null; let innerModal = null;
@ -55,6 +57,9 @@
declareRef: (ref) => { declareRef: (ref) => {
buttonRef = ref; buttonRef = ref;
}, },
updateLabel: (value) => {
label.set(value);
},
}); });
function focus(element) { function focus(element) {
@ -119,6 +124,9 @@
> >
<div <div
bind:this="{innerModal}" bind:this="{innerModal}"
role="dialog"
aria-modal="true"
aria-label="{$$props['aria-label'] || $label || undefined}"
class:bx--modal-container="{true}" class:bx--modal-container="{true}"
class:bx--modal-container--xs="{size === 'xs'}" class:bx--modal-container--xs="{size === 'xs'}"
class:bx--modal-container--sm="{size === 'sm'}" class:bx--modal-container--sm="{size === 'sm'}"

View file

@ -23,27 +23,29 @@
import { getContext } from "svelte"; import { getContext } from "svelte";
import Close20 from "carbon-icons-svelte/lib/Close20/Close20.svelte"; import Close20 from "carbon-icons-svelte/lib/Close20/Close20.svelte";
const { closeModal } = getContext("ComposedModal"); const { closeModal, updateLabel } = getContext("ComposedModal");
$: updateLabel(label);
</script> </script>
<div class:bx--modal-header="{true}" {...$$restProps}> <div class:bx--modal-header="{true}" {...$$restProps}>
{#if label} {#if label}
<p <h2
class:bx--modal-header__label="{true}" class:bx--modal-header__label="{true}"
class:bx--type-delta="{true}" class:bx--type-delta="{true}"
class="{labelClass}" class="{labelClass}"
> >
{label} {label}
</p> </h2>
{/if} {/if}
{#if title} {#if title}
<p <h3
class:bx--modal-header__heading="{true}" class:bx--modal-header__heading="{true}"
class:bx--type-beta="{true}" class:bx--type-beta="{true}"
class="{titleClass}" class="{titleClass}"
> >
{title} {title}
</p> </h3>
{/if} {/if}
<slot /> <slot />
<button <button