Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(Layout): a11y enhancements for fold button #557

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 16 additions & 4 deletions src/Layout/Layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import {
mergeProps,
} from 'vue'
import { RouterView, RouteLocationNormalizedLoaded } from 'vue-router'
import { ElScrollbar, useAttrs } from 'element-plus'
import { ElScrollbar, useAttrs, useId } from 'element-plus'
import {
useCurrentBreakpoint,
useLocale,
useShow,
useSplitReactive,
} from '../composables/index'
Expand All @@ -36,6 +37,9 @@ export default defineComponent({
const attrs = useAttrs()
const breakpoint = useCurrentBreakpoint()
const { show, toggleShow } = useShow(props.collapse)
const { t } = useLocale()
const id = useId()

const collapse = computed(() => {
return breakpoint.value === 'xs' ? false : show.value
})
Expand Down Expand Up @@ -63,8 +67,13 @@ export default defineComponent({

function createMenuButton() {
return h(
'span',
'button',
{
type: 'button',
ariaDisabled: false,
ariaControls: id.value,
ariaExpanded: !collapse.value,
ariaLabel: t('pro.layout.ariaToggle'),
class: ['header-fold-btn', collapse.value && 'is-active'],
onClick: toggleShow,
},
Expand All @@ -79,11 +88,14 @@ export default defineComponent({
function createAside() {
return h(
'aside',
{ class: ['pro-aside', show.value && 'aside-collapse'] },
{
id: id.value,
class: ['pro-aside', show.value && 'aside-collapse'],
},
[
h('div', { class: 'mask', onClick: toggleShow }),
h(
'div',
'nav',
{
class: [
'pro-aside-wrapper',
Expand Down
3 changes: 3 additions & 0 deletions src/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ export default {
right: 'Close Right',
others: 'Close Others',
},
layout: {
ariaToggle: 'Toggle sidebar menu content',
},
},
}
3 changes: 3 additions & 0 deletions src/locale/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ export default {
right: '关闭右侧',
others: '关闭其他',
},
layout: {
ariaToggle: '切换侧边栏菜单内容',
},
},
}
5 changes: 4 additions & 1 deletion src/styles/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ body {
}
& .header-fold-btn {
display: inline-block;
margin-right: 20px;
margin: 0px 20px 0px 0px;
padding: 0;
width: 24px;
height: 29px;
border: 0;
background-color: transparent;
cursor: pointer;
& .line {
display: block;
Expand Down
Loading