Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 739603 of Usando o atributo aria-labelledby

  • Slug da revisão: Web/Accessibility/ARIA/ARIA_Techniques/Usando_o_atributo_aria-labelledby
  • Título da revisão: Usando o atributo aria-labelledby
  • ID da revisão: 739603
  • Criado:
  • Criador: eduardojmatos
  • É a revisão atual? Não
  • Comentar

Conteúdo da revisão

Descrição

Essa técnica demonstra como usar o atributo aria-labelledby.

O atributo aria-labelledby é usado para indicar os IDs de elementos que são os rótulos para o objeto. É usado para estabelecer uma relação entre widgets ou grupos e suas labels. Usuários de tecnologias assistivas como leitores de telas navegam tipicamente uma página através de TABs entre as áreas da tela. Se uma label não está associada com um elemento input, widget ou grupo, não será legível por leitor de tela.

aria-labelledby é muito similar ao aria-describedby: uma label descreve a essência de um objeto, enquanto uma descrição prove mais informação que o usuário pode precisar.

O atributo aria-labelledby não é usado somente para elementos de formulário; é também usado para associar texto estático com widgets, grupos de elementos, painéis, regiões que tem um cabeçalho, definições e mais. A seção {{ anch("Exemplos") }} abaixo fornece mais informação sobre como usar os atibutos nesses casos.

aria-labelledby pode ser usadas em conjunto com o elemento {{ HTMLElement("label") }} (usando o atributo for) para melhorar a compatibilidade com user agents que não suportam ainda ARIA.

Esse atributo pode ser usando com qualquer elemento HTML de formulário; não é limitado a elementos que tem uma role ARIA atribuída.

Value

Uma lista separadas por espaço de IDs do elemento

Possíveis efeitos em user agents e tecnologias assistivas 

Quando ambos aria-labelledby e aria-label são usados, user agents dão precedência ao aria-labelledby quando computam o nome da propriedade acessível.

Nota: Opinões podem diferir em como as tecnologias assistivas devem manipular essa técnica. A informação fornecida acima é uma dessas opiniões e portanto não normativa.

Exemplos

Exemplo 1: Múltiplas Labels

No exemplo abaixo, cada campo input é rotulado por ambos tanto por seu próprio rótulo individual como para o rótulo para o grupo:

<div id="billing">Endereço de Cobrança</div>

<div>
    <div id="name">Nome</div>
    <input type="text" aria-labelledby="name billing"/>
</div>
<div>
    <div id="address">Endereço</div>
    <input type="text" aria-labelledby="address billing"/>
</div>

Exemplo 2: Associando Cabeçalhos com Regiões

No exemplo abaixo, elementos de cabeçalho estão associados com o conteúdo que eles seguem. Note que a região sendo referenciada é a que contem o cabeçalho.

<div role="main" aria-labelledby="foo">
   <h1 id="foo">Incêndios selvagens se espalham por San Diego Hills</h1>
   Fortes ventos expandem o fogo inflamado pelas altas temperaturas ...
</div>

Exemplo 3: Radio Groups

No exemplo abaixo,  o container de um radiogroup  é associado com suas labels usando o atributo aria-labelledby:

<div id="radio_label">Meu radio label</div>
<ul role="radiogroup" aria-labelledby="radio_label">
    <li role="radio">Item #1</li>
    <li role="radio">Item #2</li>
    <li role="radio">Item #3</li>
</ul>

Exemplo 4: Dialog Label

In the example below, the header element that labels the dialog is referred to by the aria-labelledby attribute:

<div role="dialog" aria-labelledby="dialogheader">
    <h2 id="dialogheader">Choose a File</h2>
    ... Dialog contents
</div>

Example 5: Inline Definition

In the example below, the definition of a term that is described in the natural flow of the narrative is associated with the term itself using the aria-labelledby attribute:

<p>The doctor explained it had been a <dfn id="placebo">placebo</dfn>, or <span role="definition" aria-labelledby="placebo">  
or an inert preparation prescribed more for the mental relief of the patient than for its actual effect on a disorder.</span>
</p>

Example 6: Definition Lists

In the example below, the definitions in a formal definition list are associated with the terms they define using the aria-labelledby attribute:

<dl>
    <dt id="anathema">anthema</dt>
    <dd role="definition" aria-labelledby="anathema">a ban or curse solemnly pronounced by ecclesiastical authority
                                                     and accompanied by excommunication</dd>
    <dd role="definition" aria-labelledby="anathema">a vigorous denunciation : cursor</dd>

    <dt id="homily">homily</dt>
    <dd role="definition" aria-labelledby="homily">a usually short sermon</dd>
    <dd role="definition" aria-labelledby="homily">a lecture or discourse on or of a moral theme</dd>

</dl>

Example 7: Menus

In the example below, a popup menu is associated with its label using the aria-labelledby attribute:

<div role="menubar">
    <div role="menuitem" aria-haspopup="true" id="fileMenu">File</div>
    <div role="menu" aria-labelledby="fileMenu">
        <div role="menuitem">Open</div>
        <div role="menuitem">Save</div>
        <div role="menuitem">Save as ...</div>
        ...
    </div>
    ...
</div>

Working Examples:

Notes 

The most common accessibility API mapping for a label is the accessible name property

Used by ARIA roles

all elements of the base markup

Compatibility

TBD: Add support information for common UA and AT product combinations

Additional resources

Fonte da revisão

<h3 id="Description">Descrição</h3>

<p>Essa técnica demonstra como usar o atributo&nbsp;<a class="external" href="https://www.w3.org/TR/wai-aria/states_and_properties#aria-labelledby" rel="external" target="_blank" title="https://www.w3.org/TR/wai-aria/states_and_properties#aria-labelledby"><code>aria-labelledby</code></a>.</p>

<p>O atributo&nbsp;<code>aria-labelledby</code>&nbsp;é usado para indicar os IDs de elementos que são os rótulos para o objeto. É usado para estabelecer uma relação entre widgets ou grupos e suas&nbsp;labels. Usuários de tecnologias assistivas como leitores de telas navegam tipicamente uma página através de TABs entre as áreas da tela. Se uma label não está associada com um elemento input, widget ou grupo, não será legível por leitor de tela.</p>

<p><code>aria-labelledby</code>&nbsp;é muito similar ao&nbsp;<a href="/en/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute" title="en/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute">aria-describedby</a>: uma label descreve a essência de um objeto, enquanto uma descrição prove mais informação que o usuário pode precisar.</p>

<p>O atributo&nbsp;<code>aria-labelledby</code> não é usado somente para elementos de formulário; é também usado para associar texto estático com widgets, grupos de elementos, painéis, regiões que tem um cabeçalho, definições e mais. A seção {{ anch("Exemplos") }} abaixo fornece mais informação sobre como usar os atibutos nesses casos.</p>

<p><code>aria-labelledby</code>&nbsp;pode ser usadas em conjunto com o elemento {{ HTMLElement("label") }} (usando o atributo&nbsp;<code style="font-style: normal;">for</code>) para melhorar a compatibilidade com user agents que não suportam ainda ARIA.</p>

<p>Esse atributo pode ser usando com qualquer elemento HTML de formulário; não é limitado a elementos que tem uma&nbsp;<span style="font-family: Consolas, Monaco, 'Andale Mono', monospace;">role</span>&nbsp;ARIA atribuída.</p>

<h3 id="Value">Value</h3>

<p>Uma lista separadas por espaço de IDs do elemento</p>

<h3 id="Possible_effects_on_user_agents_and_assistive_technology.C2.A0">Possíveis efeitos em user agents e tecnologias assistivas&nbsp;</h3>

<p>Quando ambos&nbsp;<code>aria-labelledby</code> e <a href="/en/ARIA/ARIA_Techniques/Using_the_aria-label_attribute" title="Using the aria-labelledby attribute"><code>aria-label</code></a>&nbsp;são usados, user agents dão precedência ao&nbsp;<code>aria-labelledby</code>&nbsp;quando computam o nome da propriedade acessível.</p>

<div class="note"><strong>Nota:</strong>&nbsp;Opinões podem diferir em como as tecnologias assistivas devem manipular essa técnica. A informação fornecida acima é uma dessas opiniões e portanto não normativa.</div>

<h3 id="Examples">Exemplos</h3>

<h4 id="Example_1.3A_Multiple_Labels">Exemplo&nbsp;1: Múltiplas Labels</h4>

<p>No exemplo abaixo, cada campo input é rotulado por ambos tanto por seu próprio rótulo individual como para o rótulo para o grupo:</p>

<pre class="brush: html">
&lt;div id="billing"&gt;Endereço de Cobrança&lt;/div&gt;

&lt;div&gt;
    &lt;div id="name"&gt;Nome&lt;/div&gt;
    &lt;input type="text" aria-labelledby="name billing"/&gt;
&lt;/div&gt;
&lt;div&gt;
    &lt;div id="address"&gt;Endereço&lt;/div&gt;
    &lt;input type="text" aria-labelledby="address billing"/&gt;
&lt;/div&gt;
</pre>

<h4 id="Example_2.3A_Associating_Headers_With_Regions">Exemplo&nbsp;2: Associando Cabeçalhos com Regiões</h4>

<p>No exemplo abaixo, elementos de cabeçalho estão associados com o conteúdo que eles seguem. Note que a região sendo referenciada é a que <em>contem</em> o cabeçalho.</p>

<pre class="brush: html">
&lt;div role="main" aria-labelledby="foo"&gt;
   &lt;h1 id="foo"&gt;Incêndios selvagens se espalham por San Diego Hills&lt;/h1&gt;
   Fortes ventos expandem o fogo inflamado pelas altas temperaturas ...
&lt;/div&gt;
</pre>

<h4 id="Example_3.3A_Radio_Groups">Exemplo&nbsp;3: Radio Groups</h4>

<p>No exemplo abaixo, &nbsp;o container de um&nbsp;<a href="/en/Accessibility/ARIA/ARIA_Techniques/Using_the_radiogroup_role" title="Using the alert role">radiogroup</a>&nbsp; é associado com suas labels usando o atributo&nbsp;<code>aria-labelledby</code>:</p>

<pre class="brush: html">
&lt;div id="radio_label"&gt;Meu radio label&lt;/div&gt;
&lt;ul role="radiogroup" aria-labelledby="radio_label"&gt;
    &lt;li role="radio"&gt;Item #1&lt;/li&gt;
    &lt;li role="radio"&gt;Item #2&lt;/li&gt;
    &lt;li role="radio"&gt;Item #3&lt;/li&gt;
&lt;/ul&gt;
</pre>

<h4 id="Example_4.3A_Dialog_Label">Exemplo 4: Dialog Label</h4>

<p>In the example below, the header element that labels the dialog is referred to by the <code>aria-labelledby</code> attribute:</p>

<pre class="brush: html">
&lt;div role="dialog" aria-labelledby="dialogheader"&gt;
    &lt;h2 id="dialogheader"&gt;Choose a File&lt;/h2&gt;
    ... Dialog contents
&lt;/div&gt;
</pre>

<h4 id="Example_5.3A_Inline_Definition">Example 5: Inline Definition</h4>

<p>In the example below, the definition of a term that is described in the natural flow of the narrative is associated with the term itself using the <strong>aria-labelledby</strong> attribute:</p>

<pre class="brush: html">
&lt;p&gt;The doctor explained it had been a &lt;dfn id="placebo"&gt;placebo&lt;/dfn&gt;, or &lt;span role="definition" aria-labelledby="placebo"&gt;  
or an inert preparation prescribed more for the mental relief of the patient than for its actual effect on a disorder.&lt;/span&gt;
&lt;/p&gt;
</pre>

<h4 id="Example_6.3A_Definition_Lists">Example 6: Definition Lists</h4>

<p>In the example below, the definitions in a formal definition list are associated with the terms they define using the <code>aria-labelledby</code> attribute:</p>

<pre class="brush: html">
&lt;dl&gt;
    &lt;dt id="anathema"&gt;anthema&lt;/dt&gt;
    &lt;dd role="definition" aria-labelledby="anathema"&gt;a ban or curse solemnly pronounced by ecclesiastical authority
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and accompanied by excommunication&lt;/dd&gt;
    &lt;dd role="definition" aria-labelledby="anathema"&gt;a vigorous denunciation : cursor&lt;/dd&gt;

    &lt;dt id="homily"&gt;homily&lt;/dt&gt;
    &lt;dd role="definition" aria-labelledby="homily"&gt;a usually short sermon&lt;/dd&gt;
    &lt;dd role="definition" aria-labelledby="homily"&gt;a lecture or discourse on or of a moral theme&lt;/dd&gt;

&lt;/dl&gt;
</pre>

<h4 id="Example_7.3A_Menus">Example 7: Menus</h4>

<p>In the example below, a <a href="/en/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-haspopup_attribute" title="Using the aria-required attribute">popup menu</a> is associated with its label using the <code>aria-labelledby</code> attribute:</p>

<pre class="brush: html">
&lt;div role="menubar"&gt;
    &lt;div role="menuitem" aria-haspopup="true" id="fileMenu"&gt;File&lt;/div&gt;
    &lt;div role="menu" aria-labelledby="fileMenu"&gt;
        &lt;div role="menuitem"&gt;Open&lt;/div&gt;
        &lt;div role="menuitem"&gt;Save&lt;/div&gt;
        &lt;div role="menuitem"&gt;Save as ...&lt;/div&gt;
        ...
    &lt;/div&gt;
    ...
&lt;/div&gt;
</pre>

<h4 id="Working_Examples.3A">Working Examples:</h4>

<ul>
 <li><a class="external" href="https://www.oaa-accessibility.org/examplep/button2/" title="https://www.oaa-accessibility.org/examplep/button2/">Button example</a> uses <code>aria-labelledby</code></li>
 <li><a class="external" href="https://www.oaa-accessibility.org/examplep/combobox1/" title="https://www.oaa-accessibility.org/examplep/combobox1/">Combobox example</a> uses <code>aria-labelledby</code></li>
</ul>

<h3 id="Notes.C2.A0">Notes&nbsp;</h3>

<p>The most common <em>accessibility API</em> mapping for a label is the <em>accessible name</em> property</p>

<h3 id="Used_by_ARIA_roles">Used by ARIA roles</h3>

<p>all elements of the base markup</p>

<h3 id="Related_ARIA_techniques.C2.A0">Related ARIA techniques&nbsp;</h3>

<ul>
 <li><a href="/en/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute" title="en/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute">Using the aria-label attribute</a></li>
 <li><a href="/en/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute" title="en/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute">Using the aria-describedby attribute</a></li>
</ul>

<h3 id="Compatibility">Compatibility</h3>

<p class="comment">TBD: Add support information for common UA and AT product combinations</p>

<h3 id="Additional_resources">Additional resources</h3>

<ul>
 <li><a class="external" href="https://www.w3.org/TR/wai-aria/states_and_properties#aria-labelledby" title="https://www.w3.org/TR/wai-aria/states_and_properties#aria-labelledby">WAI-ARIA specification for aria-labelledby</a></li>
</ul>
Reverter para esta revisão