Skip to content

Commit

Permalink
add ariaLiveOnly push option and listAriaLabel Notivue prop
Browse files Browse the repository at this point in the history
  • Loading branch information
smastrom committed Aug 12, 2023
1 parent 63b56a1 commit 4af00f4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 87 deletions.
85 changes: 0 additions & 85 deletions demo/components/App.vue

This file was deleted.

19 changes: 19 additions & 0 deletions packages/notivue/Notivue/AriaLive.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script setup lang="ts">
import { getAriaLabel as getAriaLiveContent } from './utils'
import { NotivueSlot } from 'notivue'
const props = defineProps<{
item: NotivueSlot
}>()
</script>

<template>
<div
aria-atomic="true"
:role="props.item.ariaRole"
:aria-live="props.item.ariaLive"
:key="`${item.id}_${item.type}`"
>
{{ getAriaLiveContent(props.item) }}
</div>
</template>
18 changes: 16 additions & 2 deletions packages/notivue/Notivue/Notivue.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script setup lang="ts">
import { Teleport, onBeforeUnmount, type Component } from 'vue'
import AriaLive from './AriaLive.vue'
import { useNotivue, useItems, useElements } from '@/core/useStore'
import { useMouseEvents } from './composables/useMouseEvents'
Expand All @@ -21,9 +23,17 @@ interface NotivueProps {
* Notification containers tabIndex map. Only needed if using NotivueKeyboard.
*/
containersTabIndex?: ContainerTabIndexMap
/**
* Aria label for the list container. Only effective if using NotivueKeyboard.
*
* @default 'Notifications List'
*/
listAriaLabel?: string
}
const props = defineProps<NotivueProps>()
const props = withDefaults(defineProps<NotivueProps>(), {
listAriaLabel: 'Notifications List',
})
defineSlots<{
default(item: NotivueSlot & { key?: string }): Component
Expand Down Expand Up @@ -55,7 +65,7 @@ onBeforeUnmount(() => {
<Teleport :to="config.teleportTo.value">
<!-- List Container -->
<ol
aria-label="Notifications List"
:aria-label="props.listAriaLabel"
v-if="items.entries.value.length > 0"
v-bind="{ ...mouseEvents, ...touchEvents }"
:data-notivue-align="config.isTopAlign.value ? 'top' : 'bottom'"
Expand All @@ -77,8 +87,12 @@ onBeforeUnmount(() => {
...item.positionStyles,
}"
>
<!-- ariaLiveOnly Push Option -->
<AriaLive v-if="item.ariaLiveOnly" :item="item" />

<!-- Notification Container -->
<div
v-else
:aria-label="getAriaLabel(item)"
:tabindex="containersTabIndex?.[item.id] ?? -1"
:data-notivue-container="item.id"
Expand Down
1 change: 1 addition & 0 deletions packages/notivue/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export interface PushProps<T extends Obj = Obj> {

export interface PushSpecificOptions {
skipQueue?: boolean
ariaLiveOnly?: boolean
}

/** Defined by the user when calling push() */
Expand Down

0 comments on commit 4af00f4

Please sign in to comment.