Skip to content
Open
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
14 changes: 14 additions & 0 deletions packages/optimus-ui/src/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ export class ButtonDirective extends BaseComponent {
<button
[attr.type]="type || buttonProps?.type"
[attr.aria-label]="ariaLabel || buttonProps?.ariaLabel"
[attr.aria-controls]="ariaControls || buttonProps?.ariaControls"
[attr.aria-expanded]="ariaExpanded ?? buttonProps?.ariaExpanded"
[ngStyle]="style || buttonProps?.style"
[disabled]="disabled || loading || buttonProps?.disabled"
[class]="cn(cx('root'), styleClass, buttonProps?.styleClass)"
Expand Down Expand Up @@ -749,6 +751,18 @@ export class Button extends BaseComponent<ButtonPassThrough> {
*/
@Input() ariaLabel: string | undefined;

/**
* Defines the element controlled by the button.
* @group Props
*/
@Input() ariaControls: string | undefined;

/**
* Defines whether the controlled element is expanded.
* @group Props
*/
@Input({ transform: booleanAttribute }) ariaExpanded: boolean | undefined;

/**
* When present, it specifies that the component should automatically get focus on load.
* @group Props
Expand Down
12 changes: 6 additions & 6 deletions packages/optimus-ui/src/panel/panel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ describe('Panel', () => {
testFixture.changeDetectorRef.markForCheck();
await testFixture.whenStable();

const toggleButton = testFixture.debugElement.query(By.css('p-button'));
const toggleButton = testFixture.debugElement.query(By.css('p-button button'));
expect(toggleButton.nativeElement.getAttribute('aria-expanded')).toBe((!panelInstance.collapsed).toString());

testComponent.collapsed = true;
Expand Down Expand Up @@ -475,12 +475,12 @@ describe('Panel', () => {
testFixture.changeDetectorRef.markForCheck();
await testFixture.whenStable();

const toggleButton = testFixture.debugElement.query(By.css('p-button'));
const toggleButton = testFixture.debugElement.query(By.css('p-button button'));
const contentContainer = testFixture.debugElement.query(By.css('.p-panel-content-container'));

expect(toggleButton.nativeElement.getAttribute('role')).toBe('button');
expect(toggleButton.nativeElement.getAttribute('aria-expanded')).toBeTruthy();
expect(toggleButton.nativeElement.getAttribute('aria-controls')).toBeTruthy();
expect(toggleButton.nativeElement.tagName).toBe('BUTTON');
expect(toggleButton.nativeElement.getAttribute('aria-expanded')).toBe('true');
expect(toggleButton.nativeElement.getAttribute('aria-controls')).toBe(contentContainer.nativeElement.id);
expect(toggleButton.nativeElement.getAttribute('aria-label')).toBe(testComponent.header);

expect(contentContainer.nativeElement.getAttribute('role')).toBe('region');
Expand All @@ -493,7 +493,7 @@ describe('Panel', () => {
testFixture.changeDetectorRef.markForCheck();
await testFixture.whenStable();

const toggleButton = testFixture.debugElement.query(By.css('p-button'));
const toggleButton = testFixture.debugElement.query(By.css('p-button button'));
expect(toggleButton.nativeElement.getAttribute('aria-expanded')).toBe((!panelInstance.collapsed).toString());

testComponent.collapsed = true;
Expand Down
3 changes: 3 additions & 0 deletions packages/optimus-ui/src/panel/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const PANEL_INSTANCE = new InjectionToken<Panel>('PANEL_INSTANCE');
type="button"
role="button"
[styleClass]="cx('pcToggleButton')"
[ariaLabel]="buttonAriaLabel"
[ariaControls]="id + '_content'"
[ariaExpanded]="!collapsed"
[attr.aria-label]="buttonAriaLabel"
[attr.aria-controls]="id + '_content'"
[attr.aria-expanded]="!collapsed"
Expand Down
2 changes: 2 additions & 0 deletions packages/optimus-ui/src/types/button/button.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export interface ButtonProps {
badgeClass?: string | undefined;
badgeSeverity?: 'success' | 'info' | 'warning' | 'danger' | 'help' | 'primary' | 'secondary' | 'contrast' | null | undefined;
ariaLabel?: string | undefined;
ariaControls?: string | undefined;
ariaExpanded?: boolean | undefined;
autofocus?: boolean | undefined;
variant?: string | undefined;
}
Expand Down