Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Minor fixes and improvements in theCAccordion andCNavGroup component#296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mrholek merged 2 commits intocoreui:mainfrommrholek:main
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
refactor(CAccordion): improve component accessibility
  • Loading branch information
@mrholek
mrholek committedJan 7, 2025
commit8c2827790d607a449aeafc821a80d7848a8438ba
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,11 +4,12 @@ import { CCollapse } from '../collapse/CCollapse'
const CAccordionBody = defineComponent({
name: 'CAccordionBody',
setup(_, { slots }) {
const id = inject('id')
const visible = inject('visible') as Ref<boolean>
return () =>
h(
CCollapse,
{ class: 'accordion-collapse', visible: visible.value },
{ class: 'accordion-collapse',id,visible: visible.value },
{
default: () => h('div', { class: ['accordion-body'] }, slots.default && slots.default()),
},
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ import { defineComponent, h, inject, Ref } from 'vue'
const CAccordionButton = defineComponent({
name: 'CAccordionButton',
setup(_, { slots }) {
const id = inject('id') as string
const toggleVisibility = inject('toggleVisibility') as () => void
const visible = inject('visible') as Ref<boolean>

Expand All@@ -11,7 +12,8 @@ const CAccordionButton = defineComponent({
'button',
{
type: 'button',
'aria-expanded': !visible.value,
'aria-control': id,
'aria-expanded': visible.value,
class: ['accordion-button', { ['collapsed']: !visible.value }],
onClick: () => toggleVisibility(),
},
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
import { defineComponent, h, inject, provide, ref, watch, Ref } from 'vue'
import { defineComponent, h, inject, provide, ref, watch, Ref, useId } from 'vue'

const CAccordionItem = defineComponent({
name: 'CAccordionItem',
props: {
/**
* The id global attribute defines an identifier (ID) that must be unique in the whole document.
*/
id: String,
/**
* The item key.
*/
Expand All@@ -13,16 +17,20 @@ const CAccordionItem = defineComponent({
const alwaysOpen = inject('alwaysOpen') as boolean
const setActiveItemKey = inject('setActiveItemKey') as (key: number | string) => void

const itemKey = ref(props.itemKey ?? Math.random().toString(36).slice(2, 11))
const id = props.id ?? useId()
const itemKey = ref(props.itemKey ?? id)
const visible = ref(Boolean(activeItemKey.value === itemKey.value))

watch(activeItemKey, () => (visible.value = Boolean(activeItemKey.value === itemKey.value)))

const toggleVisibility = () => {
visible.value = !visible.value
!alwaysOpen && visible && setActiveItemKey(itemKey.value)
if (!alwaysOpen && visible) {
setActiveItemKey(itemKey.value)
}
}

provide('id', id)
provide('visible', visible)
provide('toggleVisibility', toggleVisibility)

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp