Skip to content

feat: add delegation strategy to @attr mode #6358

Open

Description

🙋 Feature Request

Add the ability to proxy attributes to an internal node and never reflect them on the DOM element.

This is useful for aria-* attributes or role which makes more sense to set on an internal element within a host's shadow rather than the host itself.

🤔 Expected Behavior

@attr mode can be leveraged and allow additional strategy like "never" (or "delegate" or "proxy").

😯 Current Behavior

@attr mode allow only the following "reflect" | "boolean" | "fromView"

This might be opinionated, but our code style approach is to try and avoid DOM elements from mutating at run-time and keep a consistent result to what authors write and expect, making custom elements behave like black-box services.

in the following FAST menu item, role assigned with a default value will mutate and apply a role on the host when authors aren't setting it.

@attr
public role: MenuItemRole = MenuItemRole.menuitem;

Now this might conflict with the fact that attribute set by author would be removed at run-time when @attr is set to 'never | proxy | delegate'. but it's mandatory to avoid screenreader conflicts.

💻 Examples

Material team has written a decorator dedicated for this type of behavior and it is explained very well here

https://github.com/material-components/material-web/blob/5241b76dcabfe4a0d9a1010d90aaed65e3875c04/decorators/aria-property.ts#L9-L34

A property decorator that helps proxy an aria attribute to an internal node.

This decorator is only intended for use with ARIAMixin properties,
such as ariaLabel, to help with screen readers.

This decorator will remove the host aria-* attribute at runtime and add it
to a data-aria-* attribute to avoid screenreader conflicts between the
host and internal node.

@ariaProperty decorated properties should sync with LitElement to the
data-aria-* attribute, not the native aria-* attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions