Skip to content

It's not possible to access a kebab-cased attribute as camel-case and other way around in attrs  #4998

@sevilyilmaz

Description

@sevilyilmaz

Version

3.2.22

Reproduction link

sfc.vuejs.org/

Steps to reproduce

  • Pass an aria-label to a component with :aria-label="foo" and :ariaLabel="foo"
  • Read the attribute in the component with the attrs parameter.

Parent.vue

<script setup>
import { ref } from 'vue'
import Comp from './Comp.vue';

const ariaLabel = 'This is an aria-label';
</script>

<template>
  <Comp aria-label="This is an aria-label" />
  <Comp :aria-label="ariaLabel" />
  <Comp :ariaLabel="ariaLabel" />
</template>

Comp.vue

<script setup>
import { ref, useAttrs, computed } from 'vue'

const attrs = useAttrs();
const hasKebabCaseAriaLabel = computed(() => Boolean(attrs['aria-label']));
const hasCamelCaseAriaLabel = computed(() => Boolean(attrs.ariaLabel));
</script>

<template>
  <div>
    <div>
      kebab-case attr: {{ hasKebabCaseAriaLabel }}
    </div>
    <div>
      camelCase attr: {{ hasCamelCaseAriaLabel }}
    </div>
    
    <hr />
  </div>
</template>

Output:

kebab-case attr: true
camelCase attr: false
---
kebab-case attr: true
camelCase attr: false
---
kebab-case attr: false
camelCase attr: true
<div aria-label="This is an aria-label"></div>
<div aria-label="This is an aria-label"></div>
<div aria-label="This is an aria-label"></div>

What is expected?

Vue should be able to infer an attribute regardless of is case as they are used camel-cased in the HTML.

aria-label in this example, will be used as camel-case in all three usages.

What is actually happening?

When aria-label is passed with kebab-case attrs.ariaLabel returns undefined and when it's passed with camel-case attrs['aria-label'] returns undefined.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions