Skip to content

Commit

Permalink
feat(elements|ino-select): improve accessibility (#1055)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan-Niklas <jan-niklas.voss@inovex.de>
  • Loading branch information
Sl1nd and janivo authored Sep 12, 2023
1 parent c1279b6 commit d370dc2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
3 changes: 1 addition & 2 deletions packages/elements/src/components/ino-option/ino-option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ export class InoOption {
});

return (
<Host>
<Host role="option">
<li
class={classSelect}
data-value={this.value}
aria-selected={this.selected}
>
<span class="mdc-deprecated-list-item__text">
<slot />
Expand Down
23 changes: 20 additions & 3 deletions packages/elements/src/components/ino-select/ino-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Watch,
} from '@stencil/core';
import classNames from 'classnames';
import { hasSlotContent } from '../../util/component-utils';
import { generateUniqueId, hasSlotContent } from '../../util/component-utils';

/**
* @slot icon-leading - For the icon to be prepended
Expand All @@ -32,6 +32,13 @@ export class Select implements ComponentInterface {
private nativeInputElement?: HTMLInputElement;
private optionsObserver: MutationObserver;

/**
* An internal auto generated id for the helper field.
*/
private selectElId = generateUniqueId();



@Element() el!: HTMLInoSelectElement;

/**
Expand Down Expand Up @@ -125,6 +132,7 @@ export class Select implements ComponentInterface {
connectedCallback() {
// in case of usage e.g. in a popover this is necessary
this.create();

this.optionsObserver = new MutationObserver(() => {
forceUpdate(this.el);
});
Expand Down Expand Up @@ -240,7 +248,12 @@ export class Select implements ComponentInterface {
<Host class={inoSelectClasses} name={this.name}>
<div class={classSelect} ref={(el) => (this.mdcSelectContainerEl = el)}>
{hiddenInput}
<div class="mdc-select__anchor" aria-required={this.required}>
<div
class="mdc-select__anchor"
role="combobox"
tabindex="0"
aria-labelledby={`label-${this.selectElId}`}
aria-required={this.required}>
{leadingSlotHasContent && (
<span class="mdc-select__icon">
<slot name="icon-leading"></slot>
Expand All @@ -249,15 +262,19 @@ export class Select implements ComponentInterface {
<div class="mdc-select__selected-text"></div>
{this.renderDropdownIcon()}
<ino-label
id={`label-${this.selectElId}`}
outline={this.outline}
text={this.label}
required={this.required}
disabled={this.disabled}
show-hint={this.showLabelHint}
/>
</div>
<div class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fullwidth">
<div
class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fullwidth">
<ul
role="listbox"
tabindex="-1"
class="mdc-deprecated-list"
ref={(el) => (this.mdcOptionsListEl = el)}
>
Expand Down

0 comments on commit d370dc2

Please sign in to comment.