mirror of
https://github.com/element-plus/element-plus.git
synced 2025-08-26 12:32:17 +08:00
fix(components): [pagination] improved keyboard accessibility (#8107)
* fix(components): [pagination] improved keyboard accessibility * refactor(components): [pagination] change arguments type * refactor(components): [pagination] change camel case
This commit is contained in:
@ -20,10 +20,13 @@
|
|||||||
nsIcon.b(),
|
nsIcon.b(),
|
||||||
nsPager.is('disabled', disabled),
|
nsPager.is('disabled', disabled),
|
||||||
]"
|
]"
|
||||||
@mouseenter="onMouseenter('left')"
|
tabindex="0"
|
||||||
|
@mouseenter="onMouseEnter(true)"
|
||||||
@mouseleave="quickPrevHover = false"
|
@mouseleave="quickPrevHover = false"
|
||||||
|
@focus="onFocus(true)"
|
||||||
|
@blur="quickPrevFocus = false"
|
||||||
>
|
>
|
||||||
<d-arrow-left v-if="quickPrevHover" />
|
<d-arrow-left v-if="quickPrevHover || quickPrevFocus" />
|
||||||
<more-filled v-else />
|
<more-filled v-else />
|
||||||
</li>
|
</li>
|
||||||
<li
|
<li
|
||||||
@ -47,10 +50,13 @@
|
|||||||
nsIcon.b(),
|
nsIcon.b(),
|
||||||
nsPager.is('disabled', disabled),
|
nsPager.is('disabled', disabled),
|
||||||
]"
|
]"
|
||||||
@mouseenter="onMouseenter('right')"
|
tabindex="0"
|
||||||
|
@mouseenter="onMouseEnter()"
|
||||||
@mouseleave="quickNextHover = false"
|
@mouseleave="quickNextHover = false"
|
||||||
|
@focus="onFocus()"
|
||||||
|
@blur="quickNextFocus = false"
|
||||||
>
|
>
|
||||||
<d-arrow-right v-if="quickNextHover" />
|
<d-arrow-right v-if="quickNextHover || quickNextFocus" />
|
||||||
<more-filled v-else />
|
<more-filled v-else />
|
||||||
</li>
|
</li>
|
||||||
<li
|
<li
|
||||||
@ -83,6 +89,8 @@ const showPrevMore = ref(false)
|
|||||||
const showNextMore = ref(false)
|
const showNextMore = ref(false)
|
||||||
const quickPrevHover = ref(false)
|
const quickPrevHover = ref(false)
|
||||||
const quickNextHover = ref(false)
|
const quickNextHover = ref(false)
|
||||||
|
const quickPrevFocus = ref(false)
|
||||||
|
const quickNextFocus = ref(false)
|
||||||
const pagers = computed(() => {
|
const pagers = computed(() => {
|
||||||
const pagerCount = props.pagerCount
|
const pagerCount = props.pagerCount
|
||||||
const halfPagerCount = (pagerCount - 1) / 2
|
const halfPagerCount = (pagerCount - 1) / 2
|
||||||
@ -133,14 +141,21 @@ watchEffect(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
function onMouseenter(direction: 'left' | 'right') {
|
function onMouseEnter(forward = false) {
|
||||||
if (props.disabled) return
|
if (props.disabled) return
|
||||||
if (direction === 'left') {
|
if (forward) {
|
||||||
quickPrevHover.value = true
|
quickPrevHover.value = true
|
||||||
} else {
|
} else {
|
||||||
quickNextHover.value = true
|
quickNextHover.value = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function onFocus(forward = false) {
|
||||||
|
if (forward) {
|
||||||
|
quickPrevFocus.value = true
|
||||||
|
} else {
|
||||||
|
quickNextFocus.value = true
|
||||||
|
}
|
||||||
|
}
|
||||||
function onEnter(e: UIEvent) {
|
function onEnter(e: UIEvent) {
|
||||||
const target = e.target as HTMLElement
|
const target = e.target as HTMLElement
|
||||||
if (
|
if (
|
||||||
@ -151,6 +166,11 @@ function onEnter(e: UIEvent) {
|
|||||||
if (newPage !== props.currentPage) {
|
if (newPage !== props.currentPage) {
|
||||||
emit('change', newPage)
|
emit('change', newPage)
|
||||||
}
|
}
|
||||||
|
} else if (
|
||||||
|
target.tagName.toLowerCase() === 'li' &&
|
||||||
|
Array.from(target.classList).includes('more')
|
||||||
|
) {
|
||||||
|
onPagerClick(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function onPagerClick(event: UIEvent) {
|
function onPagerClick(event: UIEvent) {
|
||||||
|
@ -94,6 +94,11 @@
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
width: inherit;
|
width: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:focus-visible {
|
||||||
|
outline: 1px solid getCssVar('pagination-hover-color');
|
||||||
|
color: getCssVar('pagination-hover-color');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.#{$namespace}-pager li.is-disabled {
|
.#{$namespace}-pager li.is-disabled {
|
||||||
@ -323,6 +328,11 @@
|
|||||||
svg {
|
svg {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:focus-visible {
|
||||||
|
outline: 1px solid getCssVar('pagination-hover-color');
|
||||||
|
color: getCssVar('pagination-hover-color');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.is-active + li {
|
&.is-active + li {
|
||||||
|
Reference in New Issue
Block a user