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

feat(components/popovers): implement disclosure pattern for popovers #2729

Merged
merged 3 commits into from
Sep 13, 2024
Merged
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
6 changes: 4 additions & 2 deletions .eslintrc-overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@
"@angular-eslint/template/interactive-supports-focus": ["warn"],
"@angular-eslint/template/label-has-associated-control": ["warn"],
"@angular-eslint/template/no-any": ["error"],
"@angular-eslint/template/no-call-expression": ["warn"],
"@angular-eslint/template/no-distracting-elements": ["warn"],
"@angular-eslint/template/no-inline-styles": ["warn"],
"@angular-eslint/template/no-inline-styles": [
"warn",
{ "allowBindToStyle": true, "allowNgStyle": true }
],
"@angular-eslint/template/no-interpolation-in-attributes": ["warn"],
"@angular-eslint/template/no-positive-tabindex": ["warn"],
"@angular-eslint/template/prefer-control-flow": ["warn"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
<button
class="sky-btn sky-btn-default sky-margin-inline-sm"
data-sky-id="popover-demo"
type="button"
[skyPopover]="myPopover"
[skyPopoverAlignment]="popoverAlignment"
[skyPopoverPlacement]="popoverPlacement"
data-sky-id="popover-demo"
>
Open popover on click
Open popover
</button>

<button
class="sky-btn sky-btn-link"
type="button"
[skyPopover]="myPopover"
skyPopoverTrigger="mouseenter"
>
Open popover on hover
</button>

<sky-popover
[dismissOnBlur]="dismissOnBlur"
[popoverTitle]="popoverTitle"
#myPopover
>
<sky-popover #myPopover [popoverTitle]="popoverTitle">
{{ popoverBody }}
</sky-popover>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div
skyPopoverTrigger="mouseenter"
[skyPopover]="validatorPopover"
[skyPopoverMessageStream]="popoverMessageStream"
class="sky-validator-cell"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ describe('Checkbox harness', () => {
});
const helpSvc = TestBed.inject(SkyHelpService);
const helpSpy = spyOn(helpSvc, 'openHelp');
fixture.componentInstance.helpKey = 'helpKey.html';
fixture.componentInstance.helpPopoverContent = undefined;
fixture.detectChanges();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
[labelHidden]="hidePhoneLabel"
data-sky-id="my-phone-checkbox"
formControlName="phone"
helpKey="helpKey.html"
[helpKey]="helpKey"
helpPopoverContent="(xxx)xxx-xxxx"
helpPopoverTitle="Format"
labelText="Phone"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ describe('Field group harness', () => {
const helpSvc = TestBed.inject(SkyHelpService);
const helpSpy = spyOn(helpSvc, 'openHelp');

fixture.componentInstance.helpKey = 'helpKey.html';

await fieldGroupHarness.clickHelpInline();
fixture.detectChanges();
await fixture.whenStable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class FieldGroupComponent {
public headingHidden = false;
public headingLevel: SkyFieldGroupHeadingLevel = 3;
public headingStyle: SkyFieldGroupHeadingStyle = 3;
public helpKey: string | undefined = 'helpKey.html';
public helpKey: string | undefined;
public helpPopoverContent: string | undefined = 'Popover content';
public helpPopoverTitle = 'Popover title';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class InputBoxHarnessTestComponent {
public easyModeDisabled = false;
public easyModeHelpContent: string | TemplateRef<unknown> | undefined =
'Help content';
public easyModeHelpKey: string | undefined = 'helpKey.html';
public easyModeHelpKey: string | undefined;
public easyModeHelpTitle = 'Help title';
public easyModeLabel: string | undefined = 'Last name (easy mode)';
public easyModeStacked = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,20 @@ describe('Input box harness', () => {
);
});

it('should open help popover and widget when clicked', async () => {
it('should open widget when clicked', async () => {
const { fixture, inputBoxHarness } = await setupTest({
dataSkyId: DATA_SKY_ID_EASY_MODE,
});

fixture.componentInstance.easyModeHelpKey = 'helpKey.html';

const helpSvc = TestBed.inject(SkyHelpService);
const helpSpy = spyOn(helpSvc, 'openHelp');

await inputBoxHarness.clickHelpInline();
fixture.detectChanges();
await fixture.whenStable();

await expectAsync(inputBoxHarness.getHelpPopoverContent()).toBeResolved();
expect(helpSpy).toHaveBeenCalledWith({ helpKey: 'helpKey.html' });
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Pipe, PipeTransform } from '@angular/core';

/**
* Sets the value of `aria-label` for inline help buttons.
* @internal
*/
@Pipe({
name: 'skyHelpInlineAriaLabel',
standalone: true,
})
export class SkyHelpInlineAriaLabelPipe implements PipeTransform {
public transform(
ariaLabel: string | undefined,
labelText: string | undefined,
labelledBy: string | undefined,
defaultAriaLabel: string | undefined,
): string | undefined {
if (labelledBy) {
return;
}

if (labelText) {
return labelText;
}

if (ariaLabel) {
return ariaLabel;
}

return defaultAriaLabel;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { CommonModule } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
inject,
input,
output,
} from '@angular/core';
import { SKY_HELP_GLOBAL_OPTIONS, SkyHelpService } from '@skyux/core';

/**
* @internal
*/
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [CommonModule],
selector: 'sky-help-inline-help-key-button',
standalone: true,
styleUrls: [
'./help-inline.default.component.scss',
'./help-inline.modern.component.scss',
],
template: `
<button
class="sky-help-inline"
type="button"
[attr.aria-controls]="
(helpSvc?.widgetReadyStateChange | async)
? globalOptions?.ariaControls
: null
"
[attr.aria-haspopup]="globalOptions?.ariaHaspopup"
[attr.aria-label]="ariaLabel()"
[attr.aria-labelledby]="ariaLabelledby()"
[ngClass]="{
'sky-help-inline-hidden': !helpSvc
}"
(click)="openHelpKey()"
>
<ng-content />
</button>
`,
})
export class SkyHelpInlineHelpKeyButtonComponent {
public actionClick = output<void>();
public ariaLabel = input<string | undefined>();
public ariaLabelledby = input<string | undefined>();
public helpKey = input.required<string>();

protected readonly globalOptions = inject(SKY_HELP_GLOBAL_OPTIONS, {
optional: true,
});

protected readonly helpSvc = inject(SkyHelpService, { optional: true });

protected openHelpKey(): void {
this.actionClick.emit();

this.helpSvc?.openHelp({
helpKey: this.helpKey(),
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { CommonModule } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
TemplateRef,
computed,
input,
output,
} from '@angular/core';
import { SkyPopoverModule } from '@skyux/popovers';

/**
* @internal
*/
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [CommonModule, SkyPopoverModule],
selector: 'sky-help-inline-popover-button',
standalone: true,
styleUrls: [
'./help-inline.default.component.scss',
'./help-inline.modern.component.scss',
],
template: `
<button
class="sky-help-inline"
type="button"
[attr.aria-label]="ariaLabel()"
[attr.aria-labelledby]="ariaLabelledby()"
[skyPopover]="popoverRef"
(click)="actionClick.emit()"
>
<ng-content />
</button>
<sky-popover #popoverRef [popoverTitle]="popoverTitle()">
@if (popoverTemplate(); as template) {
<ng-container *ngTemplateOutlet="template" />
} @else {
<p class="sky-help-inline-popover-text">{{ popoverContent() }}</p>
}
</sky-popover>
`,
})
export class SkyHelpInlinePopoverButtonComponent {
public actionClick = output<void>();
public ariaControls = input<string | undefined>();
public ariaLabel = input<string | undefined>();
public ariaLabelledby = input<string | undefined>();
public popoverContent = input.required<string | TemplateRef<unknown>>();
public popoverTitle = input<string | undefined>();

protected popoverTemplate = computed(() => {
const value = this.popoverContent();

if (value instanceof TemplateRef) {
return value;
}

return undefined;
});
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading