Skip to content

Commit

Permalink
fix(core,platform): make headingLevel a shared type, use for table to…
Browse files Browse the repository at this point in the history
…olbar (#12500)

* fix(core,platform): make headingLevel a shared type, use for table toolbar

* fix: use integers for heading level, not h1/h2/etc

* fix: allow for old values (h1/h2), strings, ints, to avoid breaking changes

* fix: pr comments
  • Loading branch information
mikerodonnell89 authored Oct 7, 2024
1 parent 104e1f5 commit 08f5984
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<span
role="heading"
class="fd-dynamic-page__title"
[attr.aria-level]="headingLevel()"
[attr.aria-level]="_headingLevel()"
[id]="titleId()"
[class.fd-dynamic-page__title--wrap]="titleWrap"
fdkIgnoreClickOnSelection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { DYNAMIC_PAGE_HEADER_TOKEN, DynamicPageHeader } from '@fundamental-ngx/c

import { NgTemplateOutlet } from '@angular/common';
import { IgnoreClickOnSelectionDirective, Nullable } from '@fundamental-ngx/cdk/utils';
import { HeadingLevel } from '@fundamental-ngx/core/shared';
import { DYNAMIC_PAGE_CLASS_NAME, DynamicPageResponsiveSize } from '../../constants';
import { DynamicPageHeaderSubtitleDirective } from '../../directives/dynamic-page-header-subtitle.directive';
import { DynamicPageHeaderTitleDirective } from '../../directives/dynamic-page-header-title.directive';
Expand All @@ -34,8 +35,6 @@ import { DynamicPageBreadcrumbComponent } from '../breadcrumb/dynamic-page-bread

export const ActionSquashBreakpointPx = 1280;

export type HeadingLevel = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';

let dynamicPageTitleId = 0;

@Component({
Expand Down Expand Up @@ -111,11 +110,14 @@ export class DynamicPageHeaderComponent implements OnInit, AfterViewInit, OnDest
_size: DynamicPageResponsiveSize;

/**
* The level of the Dynamic Page title
* Possible options: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
* Default: 'h2'
* Heading level of the dynamic page header title.
*/
headingLevel = input<HeadingLevel>('h2');
headingLevel = input<HeadingLevel>(2);

/** @hidden */
_headingLevel = computed(() =>
this.headingLevel() ? Number.parseInt(`${this.headingLevel()}`.replace(/\D/g, ''), 10) : undefined
);

/** Dynamic page title id, it has some default value if not set, */
titleId = input('fd-dynamic-page-title-id-' + dynamicPageTitleId++);
Expand Down
4 changes: 2 additions & 2 deletions libs/core/facets/facet/facet.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
} @else {
@if (facetTitle) {
<div
[attr.role]="!!headingLevel ? 'heading' : null"
[attr.aria-level]="headingLevel"
[attr.role]="!!_headingLevel ? 'heading' : null"
[attr.aria-level]="_headingLevel"
fd-title
[headerSize]="5"
class="fd-margin-bottom--sm"
Expand Down
14 changes: 12 additions & 2 deletions libs/core/facets/facet/facet.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@angular/core';
import { Nullable } from '@fundamental-ngx/cdk/utils';
import { FormLabelComponent } from '@fundamental-ngx/core/form';
import { HeadingLevel } from '@fundamental-ngx/core/shared';
import { TitleComponent } from '@fundamental-ngx/core/title';
import { FACET_CLASS_NAME, FacetType } from '../constants';
import { addClassNameToFacetElement } from '../utils';
Expand Down Expand Up @@ -47,10 +48,16 @@ export class FacetComponent implements AfterViewInit {
subtitle: string;

/**
* Heading level (i.e. <h1>, <h2>, etc.) of the facet title.
* Heading level of the facet title.
*/
@Input()
headingLevel: Nullable<1 | 2 | 3 | 4 | 5 | 6>;
set headingLevel(level: Nullable<HeadingLevel>) {
if (typeof level === 'number') {
this._headingLevel = level;
} else if (typeof level === 'string') {
this._headingLevel = Number.parseInt(level.replace(/\D/g, ''), 10);
}
}

/**
* id for the facet
Expand Down Expand Up @@ -81,6 +88,9 @@ export class FacetComponent implements AfterViewInit {
return this.type !== 'image' ? this.titleId : '';
}

/** @hidden */
_headingLevel: number;

/** @hidden
* the internal id for the title to be associated with the aria-labelledby
*/
Expand Down
1 change: 1 addition & 0 deletions libs/core/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './interfaces/tablist.interface';
export * from './services/value-state-message.service';
export * from './tokens/dynamic-page-header.token';
export * from './tokens/tabs.token';
export * from './types/heading-level';
19 changes: 19 additions & 0 deletions libs/core/shared/types/heading-level.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export type HeadingLevel =
| 1
| 2
| 3
| 4
| 5
| 6
| '1'
| '2'
| '3'
| '4'
| '5'
| '6'
| 'h1'
| 'h2'
| 'h3'
| 'h4'
| 'h5'
| 'h6';
4 changes: 3 additions & 1 deletion libs/core/toolbar/toolbar.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@if (title) {
<h4 fd-title class="fd-toolbar__title" [id]="titleId" #titleElement>{{ title }}</h4>
<span [attr.aria-level]="_headingLevel" fd-title class="fd-toolbar__title" [id]="titleId" #titleElement>{{
title
}}</span>
}
<ng-content></ng-content>
@if (overflownItems.length > 0) {
Expand Down
17 changes: 17 additions & 0 deletions libs/core/toolbar/toolbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
applyCssClass,
CssClassBuilder,
DynamicPortalComponent,
Nullable,
OVERFLOW_PRIORITY_SCORE,
OverflowPriority,
ResizeObserverService
Expand All @@ -38,6 +39,7 @@ import {
contentDensityObserverProviders
} from '@fundamental-ngx/core/content-density';
import { PopoverModule } from '@fundamental-ngx/core/popover';
import { HeadingLevel } from '@fundamental-ngx/core/shared';
import { TitleComponent, TitleToken } from '@fundamental-ngx/core/title';
import { BehaviorSubject, combineLatest, map, Observable, startWith } from 'rxjs';
import { ToolbarItem } from './abstract-toolbar-item.class';
Expand Down Expand Up @@ -140,6 +142,18 @@ export class ToolbarComponent implements AfterViewInit, AfterViewChecked, CssCla
@Input()
tabindex = -1;

/**
* Heading level of the toolbar title.
*/
@Input()
set headingLevel(level: Nullable<HeadingLevel>) {
if (typeof level === 'number') {
this._headingLevel = level;
} else if (typeof level === 'string') {
this._headingLevel = Number.parseInt(level.replace(/\D/g, ''), 10);
}
}

/** Toolbar Aria-label attribute. */
@Input()
@HostBinding('attr.aria-label')
Expand Down Expand Up @@ -178,6 +192,9 @@ export class ToolbarComponent implements AfterViewInit, AfterViewChecked, CssCla
/** @hidden */
overflownItems: ToolbarItem[] = [];

/** @hidden */
_headingLevel = 2;

/** HTML Element Reference. */
readonly elementRef = inject(ElementRef);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ng-template #startColumn>
<fd-dynamic-page [autoResponsive]="true" ariaLabel="Example Dynamic Page" [positionRelative]="true">
<fd-dynamic-page-header
headingLevel="2"
title="Lorem ipsum dolor sit amet, consectetur adipiscing elit"
subtitle="sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
}
<fd-dynamic-page size="large" ariaLabel="Example Dynamic Page" [autoResponsive]="false">
<fd-dynamic-page-header
headingLevel="2"
title="Lorem ipsum dolor sit amet, consectetur adipiscing elit"
subtitle="sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div class="overlay">
<fd-dynamic-page size="large" ariaLabel="Example Dynamic Page" [autoResponsive]="false">
<fd-dynamic-page-header
headingLevel="2"
title="Lorem ipsum dolor sit amet, consectetur adipiscing elit"
subtitle="sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@if (visible) {
<div class="overlay">
<fd-dynamic-page size="large" ariaLabel="Example Dynamic Page">
<fd-dynamic-page-header title="Lorem ipsum dolor sit amet, consectetur adipiscing elit">
<fd-dynamic-page-header headingLevel="2" title="Lorem ipsum dolor sit amet, consectetur adipiscing elit">
<span *fdDynamicPageHeaderTitle="let collapsed">
Lorem ipsum dolor sit amet, consectetur adipiscing elit ({{
collapsed ? 'collapsed' : 'not collapsed'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div class="overlay">
<fd-dynamic-page ariaLabel="Example Dynamic Page">
<fd-dynamic-page-header
headingLevel="2"
title="Lorem ipsum dolor sit amet, consectetur adipiscing elit"
subtitle="sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div class="overlay">
<fd-dynamic-page size="large" ariaLabel="Example Dynamic Page" [autoResponsive]="false">
<fd-dynamic-page-header
headingLevel="2"
title="Lorem ipsum dolor sit amet, consectetur adipiscing elit"
subtitle="sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<div class="overlay">
<fd-dynamic-page size="large" ariaLabel="Example Dynamic Page" [autoResponsive]="false">
<fd-dynamic-page-header
headingLevel="2"
title="Lorem ipsum dolor sit amet, consectetur adipiscing elit"
subtitle="sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
[titleId]="tableToolbarTitleId"
[title]="title && !hideItemCount ? title + ' (' + counter() + ')' : title"
[shouldOverflow]="shouldOverflow"
[headingLevel]="headingLevel"
>
@if (_tableToolbarLeftActionsComponent) {
<span fd-toolbar-item fdOverflowPriority="never">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { AsyncPipe, NgTemplateOutlet } from '@angular/common';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { Nullable } from '@fundamental-ngx/cdk/utils';
import { ButtonComponent } from '@fundamental-ngx/core/button';
import { HeadingLevel } from '@fundamental-ngx/core/shared';
import {
ToolbarComponent,
ToolbarItemDirective,
Expand Down Expand Up @@ -133,6 +134,12 @@ export class TableToolbarComponent implements TableToolbarInterface {
@Input()
disableSearch = false;

/**
* Heading level of the table toolbar title.
*/
@Input()
headingLevel: HeadingLevel = 2;

/** @hidden */
@ContentChild(TableToolbarActionsComponent)
tableToolbarActionsComponent: TableToolbarActionsComponent;
Expand Down

0 comments on commit 08f5984

Please sign in to comment.