Skip to content

Commit

Permalink
fix(VIcon): add tabindex to clickable icons
Browse files Browse the repository at this point in the history
  • Loading branch information
johnleider committed Mar 18, 2024
1 parent 2fcb029 commit 873550d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/vuetify/src/components/VIcon/VIcon.sass
Expand Up @@ -22,6 +22,10 @@
&--clickable
cursor: pointer

&--disabled
pointer-events: none
opacity: $icon-disabled-opacity

@each $name in settings.$sizes
&--size-#{$name}
font-size: calc(var(--v-icon-size-multiplier) * #{map.get($icon-sizes, $name)})
Expand Down
10 changes: 7 additions & 3 deletions packages/vuetify/src/components/VIcon/VIcon.tsx
Expand Up @@ -15,6 +15,7 @@ import { convertToUnit, flattenFragments, genericComponent, propsFactory, useRen

export const makeVIconProps = propsFactory({
color: String,
disabled: Boolean,
start: Boolean,
end: Boolean,
icon: IconValue,
Expand Down Expand Up @@ -45,6 +46,7 @@ export const VIcon = genericComponent()({
node.type === Text && node.children && typeof node.children === 'string'
)[0]?.children as string
}
const hasClick = !!(attrs.onClick || attrs.onClickOnce)

return (
<iconData.value.component
Expand All @@ -57,7 +59,8 @@ export const VIcon = genericComponent()({
sizeClasses.value,
textColorClasses.value,
{
'v-icon--clickable': !!attrs.onClick,
'v-icon--clickable': hasClick,
'v-icon--disabled': props.disabled,
'v-icon--start': props.start,
'v-icon--end': props.end,
},
Expand All @@ -72,8 +75,9 @@ export const VIcon = genericComponent()({
textColorStyles.value,
props.style,
]}
role={ attrs.onClick ? 'button' : undefined }
aria-hidden={ !attrs.onClick }
role={ hasClick ? 'button' : undefined }
aria-hidden={ !hasClick }
tabindex={ hasClick ? props.disabled ? -1 : 0 : undefined }
>
{ slotValue }
</iconData.value.component>
Expand Down
1 change: 1 addition & 0 deletions packages/vuetify/src/components/VIcon/_variables.scss
Expand Up @@ -3,6 +3,7 @@
@use '../../styles/tools';

// VIcon
$icon-disabled-opacity: 0.38 !default;
$icon-left-margin-left: map.get(settings.$grid-gutters, 'md') !default;
$icon-letter-spacing: normal !default;
$icon-line-height: 1 !default;
Expand Down

0 comments on commit 873550d

Please sign in to comment.