Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARIA attributes in ember core form components

I'd like to use ARIA attributes in Ember core form components, such input and textarea fields.

I noticed that using an aria attribute within the component in my template, it doesn't work at all

{{input aria-label="Your name"}}
{{textarea aria-label="Your address"}}

So I decided to reopen the core components in an initializer to add this attribute to the components

export default {
    name: 'reopenTextAreaComponent',

    initialize: function () {
        Ember.TextArea.reopen({
            attributeBindings: ['aria-label']
        });
    }
};

Since I did that, the performance of my application is pretty bad. The integration tests take much more time than before.

I tried not to use their components and simply a HTML tag:

<textarea {{bind-attr aria-label="Your address"}}>{{value}}</textarea>

But this doesn't compile with handlebars! It returns an error because of the {{value}} within the textarea tag.

What is the solution to avoid reopening? Should I create my own component?

Thanks

like image 431
alexmngn Avatar asked Feb 05 '15 14:02

alexmngn


People also ask

What is a component in Ember?

Ember components are used to turn markup text and styles into reusable content. Components consist of two parts: a JavaScript component file that defines behavior, and its accompanying Handlebars template that defines the markup for the component's UI. Components must have at least one dash in their name.

What is Mut in Ember?

Let's talk about Ember's {{ mut }} HTMLBars helperThe mut helper returns a mutable object which is an object that responds to update . The action helper knows about these objects and knows to call update (passing in the new value) when given a mutable object .

What is a model in Ember?

In Ember Data, models are objects that represent the underlying data that your application presents to the user. Note that Ember Data models are a different concept than the model method on Routes, although they share the same name.


2 Answers

From Ember 2.8+, the simplest way of doing this is to install ember-component-attributes, like this:

ember install ember-component-attributes

Then you can add aria-label, other ARIA attributes and whatever other attributes you might require as follows:

{{input (html-attributes aria-label="Your name")}}
{{textarea (html-attributes aria-label="Your address")}}
like image 179
casafred Avatar answered Sep 29 '22 21:09

casafred


What is the solution to avoid reopening? Should I create my own component?

Those are your two options.

I think you have the correct approach regarding the reopening of Ember.TextArea, because you want to have aria-label available on all instances.

I use a similar initializer - with one difference being that I reopen Ember.TextSupport so that both Ember.TextField and Ember.TextArea will have the aria-label binding.

// initializers/input.js

import Ember from 'ember';

export function initialize(/* application */) {

  Ember.TextSupport.reopen({
      attributeBindings: ['aria-label']
  });

}

You could try creating your own component(s) to see if there is any difference in performance, but I think reopening is the right approach in this case.

like image 30
ctcpip Avatar answered Sep 29 '22 20:09

ctcpip