Skip to content

Commit

Permalink
fix(core): segmented button accessibility improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
droshev committed Dec 1, 2023
1 parent 39b9adc commit 9cbfa4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
5 changes: 3 additions & 2 deletions libs/core/src/lib/button/button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@angular/core';
import { BaseButton } from './base-button';
import { Subscription } from 'rxjs';
import { applyCssClass, CssClassBuilder } from '@fundamental-ngx/cdk/utils';
import { applyCssClass, CssClassBuilder, FocusableItemDirective } from '@fundamental-ngx/cdk/utils';
import { ContentDensityObserver, contentDensityObserverProviders } from '@fundamental-ngx/core/content-density';

import { FD_BUTTON_COMPONENT } from './tokens';
Expand Down Expand Up @@ -47,7 +47,8 @@ import { FD_BUTTON_COMPONENT } from './tokens';
provide: FD_BUTTON_COMPONENT,
useExisting: ButtonComponent
}
]
],
hostDirectives: [FocusableItemDirective]
})
export class ButtonComponent extends BaseButton implements OnChanges, CssClassBuilder, OnInit, OnDestroy {
/** The property allows user to pass additional css classes. */
Expand Down
23 changes: 17 additions & 6 deletions libs/core/src/lib/segmented-button/segmented-button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import {
ContentChildren,
ElementRef,
forwardRef,
Host,
HostBinding,
HostListener,
Input,
OnDestroy,
Optional,
QueryList,
ViewEncapsulation
} from '@angular/core';
import { ButtonComponent, FD_BUTTON_COMPONENT } from '@fundamental-ngx/core/button';
import { filter, observeOn, startWith, takeUntil, tap } from 'rxjs/operators';
import { Subject, merge, fromEvent, asyncScheduler } from 'rxjs';
import { DestroyedService, KeyUtil } from '@fundamental-ngx/cdk/utils';
import { DestroyedService, FocusableListDirective, KeyUtil } from '@fundamental-ngx/cdk/utils';
import { ENTER, SPACE } from '@angular/cdk/keycodes';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';

Expand All @@ -40,7 +42,7 @@ export type SegmentedButtonValue = string | (string | null)[] | null;
templateUrl: './segmented-button.component.html',
styleUrls: ['./segmented-button.component.scss'],
host: {
role: 'group'
role: 'listbox'
},
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
Expand All @@ -51,7 +53,8 @@ export type SegmentedButtonValue = string | (string | null)[] | null;
multi: true
},
DestroyedService
]
],
hostDirectives: [FocusableListDirective]
})
export class SegmentedButtonComponent implements AfterViewInit, ControlValueAccessor, OnDestroy {
/** Whether segmented button is on toggle mode, which allows to toggle more than 1 button */
Expand Down Expand Up @@ -89,8 +92,13 @@ export class SegmentedButtonComponent implements AfterViewInit, ControlValueAcce
constructor(
private readonly _changeDetRef: ChangeDetectorRef,
private readonly _elementRef: ElementRef,
private readonly _onDestroy$: DestroyedService
) {}
private readonly _onDestroy$: DestroyedService,
@Optional() @Host() private focusableList: FocusableListDirective
) {
if (this.focusableList) {
this.focusableList.navigationDirection = 'horizontal';
}
}

/** @hidden */
ngAfterViewInit(): void {
Expand Down Expand Up @@ -150,7 +158,10 @@ export class SegmentedButtonComponent implements AfterViewInit, ControlValueAcce
this._onRefresh$.next();
this._toggleDisableButtons(this._isDisabled);
this._pickButtonsByValues(this._currentValue);
this._buttons.forEach((button) => this._listenToTriggerEvents(button));
this._buttons.forEach((button) => {
button.elementRef.nativeElement.role = 'option';
this._listenToTriggerEvents(button);
});
});
}

Expand Down

0 comments on commit 9cbfa4e

Please sign in to comment.