Skip to content

Conversation

leonsenft
Copy link
Contributor

Allow binding to ARIA attributes using property binding syntax without the attr. prefix. For example, [aria-label]="expr" is now valid, and equivalent to [ariaLabel]="expr". Both examples bind to either a matching input or the aria-label HTML attribute, rather than the ariaLabel DOM property.

Binding ARIA properties as attributes will ensure they are rendered correctly on the server, where the emulated DOM may not correctly reflect ARIA properties as attributes.

@leonsenft leonsenft requested a review from AndrewKushnir July 14, 2025 16:31
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: core Issues related to the framework runtime labels Jul 14, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 14, 2025
Copy link
Member

@JeanMeche JeanMeche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect at least to have some new compliance tests (probably in packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_bindings).

@pullapprove pullapprove bot requested review from jelbourn and josephperrott July 16, 2025 01:44
@leonsenft
Copy link
Contributor Author

I would expect at least to have some new compliance tests (probably in packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_bindings).

Good suggestion, thanks. Done!

@leonsenft leonsenft requested review from crisbeto, AndrewKushnir and JeanMeche and removed request for jelbourn and josephperrott July 16, 2025 01:55
@pullapprove pullapprove bot requested review from jelbourn and josephperrott July 16, 2025 01:55
Copy link
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Reviewed-for: fw-security

Allow binding to ARIA attributes using property binding syntax _without_
the `attr.` prefix. For example, `[aria-label]="expr"` is now valid, and
equivalent to `[ariaLabel]="expr"`. Both examples bind to either a
matching input or the `aria-label` HTML attribute, rather than the
`ariaLabel` DOM property.

Binding ARIA properties as attributes will ensure they are rendered
correctly on the server, where the emulated DOM may not correctly
reflect ARIA properties as attributes.

Reuse the DOM schema registry from the compiler to map property names in
type check blocks.
@leonsenft leonsenft added target: patch This PR is targeted for the next patch release and removed target: patch This PR is targeted for the next patch release labels Jul 21, 2025
@leonsenft leonsenft added the target: minor This PR is targeted for the next minor release label Jul 21, 2025
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Reviewed-for: fw-security

@@ -17,6 +17,8 @@ import {
} from '../compilation';
import * as ng from '../instruction';

const ARIA_PREFIX = 'aria';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: does having this as a constant meaningfully improve the code vs using using 'aria' and 4 inline? I don't imagine the prefix ever changing, so things would be a bit more concise without the indirection

(it's probably safe to assume a JS optimizer would do this, so it's probably not a performance concern, just a code style one, but it also wouldn't hurt to double check that)

Copy link
Contributor Author

@leonsenft leonsenft Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm not really familiar with the details of JSCompiler's optimizations so I favored avoiding repetition. For example, surely all 'aria' instances would be folded into the same constant, but what about 'aria-'? My guess is we'd then ship 'aria' and 'aria-' as separate strings, instead of just 'aria' and '-'.

Question Do we have any quick ways to evaluate the output?

Edit: I realize we might not be as concerned with the compiler (although I assume this is reused by the runtime compiler), there is a duplicate version of this function in core.

Edit: I recall that I had originally inlined the length and @crisbeto specifically requested I replace the magic number #62630 (comment)

Comment on lines +698 to +700
return name.charAt(ARIA_PREFIX.length) !== '-'
? ARIA_PREFIX + '-' + name.slice(ARIA_PREFIX.length).toLowerCase()
: name; // Property already has attribute name.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return name.charAt(ARIA_PREFIX.length) !== '-'
? ARIA_PREFIX + '-' + name.slice(ARIA_PREFIX.length).toLowerCase()
: name; // Property already has attribute name.
return name.startsWith('aria-') ?
name : `aria-${name.slice(4).toLowerCase()}`;

Is there any reason you couldn't just use startsWith here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A (undocumented) precondition of this function is that we know the name begins with aria, because that's the circumstance that leads to performing this mapping.

I'll document this precondition, but if you strongly prefer the startsWith check I can do that instead.

@leonsenft leonsenft removed the request for review from JeanMeche July 21, 2025 23:20
@leonsenft leonsenft added the action: merge The PR is ready for merge by the caretaker label Jul 21, 2025
@kirjs
Copy link
Contributor

kirjs commented Jul 22, 2025

This PR was merged into the repository by commit 4138aca.

The changes were merged into the following branches: main

@kirjs kirjs closed this in 4138aca Jul 22, 2025
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants