# Accessing Hyphenated Attributes in $attrs
## Rule
Fallthrough attributes preserve their original casing in JavaScript. Hyphenated attribute names (like `data-testid` or `aria-label`) must be accessed using bracket notation. Event listeners are exposed as camelCase functions (e.g., `@click` becomes `$attrs.onClick`).
## Why This Matters
- JavaScript identifiers cannot contain hyphens
- Using dot notation with hyphenated names causes syntax errors or undefined values
- Event listener naming follows a different convention than attribute naming
- Common source of "undefined" errors when working with attrs programmatically
## Bad Code
```vue
```
## Good Code
```vue
```
## Attribute vs Event Naming Reference
| Parent Usage | $attrs Access |
|--------------|---------------|
| `class="foo"` | `attrs.class` |
| `data-id="123"` | `attrs['data-id']` |
| `aria-label="..."` | `attrs['aria-label']` |
| `foo-bar="baz"` | `attrs['foo-bar']` |
| `@click="fn"` | `attrs.onClick` |
| `@custom-event="fn"` | `attrs.onCustomEvent` |
| `@update:modelValue="fn"` | `attrs['onUpdate:modelValue']` |
## Common Patterns
### Checking for specific attributes
```vue
```
### Filtering attributes by type
```vue
```
### Extracting data attributes
```vue
```
### Forwarding specific events
```vue
```
## TypeScript Considerations
```vue
```
## References
- [Fallthrough Attributes - Accessing in JavaScript](https://vuejs.org/guide/components/attrs.html#accessing-fallthrough-attributes-in-javascript)
- [Vue 3 $attrs Documentation](https://vuejs.org/api/component-instance.html#attrs)