question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set aria-* attributes

See original GitHub issue

Hello @yysun, thank you for your effort on building this awesome framework.

The problem I faced is I’m not able to setup aria-* attributes, aria-label in particular with JSX/TSX syntax. What is strange, I’m able to successfully set data-id attribute which is quite similar. the code to reproduce: <form role="search"><input type="search" className="hsi" aria-label="Search"/></form> do not set aria-label attribute.

As I see, the jsx/react namespace is bound to apprun itself which correctly create element structure with all attributes, then somehow it is transformed into DOM element without aria-label;

Can you point me what is wrong.

UPDATE: vdom-my.ts function updateProps(…) just recognize some attributes like data-id, and tries to set others as attributes to DOM element, but desired behaviour should be to add the attribute to internal attributes map . I’m pretty sure I can prepare a pull request with desired code, at least with aria-* subset.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
yysuncommented, May 23, 2018

Checking name === ‘role’ in stead of startsWith is fine in this case, but the bigger problem is that other non-standard / custom attributes are still not support. I was thinking perhaps it should use setAttribute in all cases instead of assigned the value to element property.

for (let name in props) {
    const value = props[name];
    if (name === 'className') name = 'class';
    if (name === 'style') {
      if (element.style.cssText) element.style.cssText = '';
      for (let s in value) {
        if (element.style[s] !== value[s]) element.style[s] = value[s];
      }
    } else if (name.startsWith('data-')) {
      const dname = name.substring(5);
      if (element.dataset[dname] !== value) element.dataset[dname] = value;
    } else {
      // if (element[name] !== value) element[name] = value;
      if (element.getAttribute(name) !== value) element.setAttribute(name, value);
      if (name === 'key' && value) keyCache[value] = element;
    }
  }

However, I am not sure if there is any limitation and performance issue with setAttribute , because the value parameter is alwsays string.

1reaction
yysuncommented, Aug 3, 2018

The camel case for data- attributes fix is in v1.15.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

ARIA - Accessibility - MDN Web Docs - Mozilla
Accessible Rich Internet Applications (ARIA) is a set of roles and attributes that define ways to make web content and web applications ...
Read more >
ARIA in HTML - W3C
Authors MAY use the ARIA role and aria-* attributes to change the exposed meaning (semantics) of HTML elements, in accordance with the ...
Read more >
What the Heck is ARIA? A Beginner's Guide to ARIA ... - Lullabot
ARIA is a set of attributes you can add to HTML elements that define ways to make web content and applications accessible to...
Read more >
ARIA | Accessibility Guidelines
An ARIA role is added via a role="<ROLE TYPE>" attribute, and does not ever change for an element once it is set. There...
Read more >
Use ARIA Attributes for JavaScript State Setting & Styling
Why not, right? You know that the web standards nut on your team is going to nag you to put them in your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found