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

fix(core): segmented button accessibility improvements #10932

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading