Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[A11Y] CSS IDs not being added automatically to form items #4999

Open
indigoxela opened this issue Mar 15, 2021 · 4 comments
Open

[A11Y] CSS IDs not being added automatically to form items #4999

indigoxela opened this issue Mar 15, 2021 · 4 comments

Comments

@indigoxela
Copy link
Member

indigoxela commented Mar 15, 2021

This popped up in another issue and I wasn't able to figure out:

Are IDs for core form items supposed to always get generated automatically, or are there valid cases, where this shouldn't happen?

The downside of a missing ID is that the for="the-input-id" attribute on the label can't get added, which means an accessibility regression.

@jenlampton jenlampton changed the title Form item ID: in which cases should the ID get created automatically? [A11Y] Form item ID: in which cases should the ID get created automatically? Aug 16, 2021
@jenlampton
Copy link
Member

Are IDs for core form items supposed to always get generated automatically

yes. The idea is that there may be any number of forms on a page (news letter signup, comment form, search box in the header, search box in the footer, etc) and by allowing core to assign the IDs, then we can ensure that each one is unique.

The downside of a missing ID is that the for="the-input-id" attribute on the label can't get added, which means an accessibility regression.

Core should be adding these automatically, too. (I know it does for radios and checkboxes). If that's not happening, maybe we should look closer at why?

@klonos klonos changed the title [A11Y] Form item ID: in which cases should the ID get created automatically? Admin bar: CSS ID not being added automatically to the search form Sep 14, 2021
@klonos
Copy link
Member

klonos commented Sep 14, 2021

In #4997, we ended up manually adding the ID in that search box, to fix accessibility:

function admin_bar_links_search() {
  $search['search'] = array(
    '#pre_render' => array(),
    '#attributes' => array(
      'class' => array('admin-bar-search'),
    ),
  );
  $search['search']['search'] = array(
    '#type' => 'search',
    '#title' => t('Admin search'),
    '#title_display' => 'invisible',
    '#attributes' => array(
      'placeholder' => t('Menu search'),
      'autocomplete' => 'off',
      'autocorrect' => 'off',
      'autocapitalize' => 'off',
    ),
    '#id' => 'admin-bar-search-items', // <-- why does this need to be added manually???
  );
  return $search;
}

@jenlampton
Copy link
Member

This is great, we can do the same thing in admin bar :D

@jenlampton jenlampton changed the title Admin bar: CSS ID not being added automatically to the search form [A11Y] Admin bar: CSS ID not being added automatically to the search form Sep 14, 2021
@klonos klonos changed the title [A11Y] Admin bar: CSS ID not being added automatically to the search form [A11Y] CSS IDs not being added automatically to form items Sep 15, 2021
@klonos
Copy link
Member

klonos commented Sep 15, 2021

Sorry @jenlampton for messing the issue title. This was already done for the admin bar; we now need to ensure that this is consistent for all form items. '#type' => 'search' seems to not be doing it automatically, so lets start with that.

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

No branches or pull requests

3 participants