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(block, date-picker, list-item-group, panel, pick-list-group, popover, tip, tip-manager)!: Set default internal heading to a div. #5728

Merged
merged 3 commits into from
Nov 16, 2022
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
4 changes: 2 additions & 2 deletions src/components/block/block.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Element, Event, EventEmitter, h, Host, Prop, VNode } from "@stencil/core";
import { CSS, HEADING_LEVEL, ICONS, SLOTS, TEXT } from "./resources";
import { CSS, ICONS, SLOTS, TEXT } from "./resources";
import { getSlotted, toAriaBoolean } from "../../utils/dom";
import { Heading, HeadingLevel } from "../functional/Heading";
import { Status } from "../interfaces";
Expand Down Expand Up @@ -216,7 +216,7 @@ export class Block implements ConditionalSlotComponent, InteractiveComponent {
const { heading, headingLevel, summary, description } = this;
return heading || summary || description ? (
<div class={CSS.title}>
<Heading class={CSS.heading} level={headingLevel || HEADING_LEVEL}>
<Heading class={CSS.heading} level={headingLevel}>
{heading}
</Heading>
{summary || description ? (
Expand Down
2 changes: 0 additions & 2 deletions src/components/block/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,3 @@ export const ICONS = {
invalid: "exclamation-mark-triangle",
refresh: "refresh"
};

export const HEADING_LEVEL = 4;
4 changes: 2 additions & 2 deletions src/components/date-picker/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { HeadingLevel } from "../functional/Heading";

import { DateRangeChange } from "./interfaces";
import { HEADING_LEVEL, TEXT } from "./resources";
import { TEXT } from "./resources";
import {
connectLocalized,
disconnectLocalized,
Expand Down Expand Up @@ -482,7 +482,7 @@ export class DatePicker implements LocalizedComponent {
this.localeData && [
<calcite-date-picker-month-header
activeDate={activeDate}
headingLevel={this.headingLevel || HEADING_LEVEL}
headingLevel={this.headingLevel}
intlNextMonth={this.intlNextMonth}
intlPrevMonth={this.intlPrevMonth}
intlYear={this.intlYear}
Expand Down
2 changes: 0 additions & 2 deletions src/components/date-picker/resources.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const HEADING_LEVEL = 2;

export const TEXT = {
nextMonth: "Next month",
prevMonth: "Previous month",
Expand Down
9 changes: 9 additions & 0 deletions src/components/functional/Heading.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ describe("Heading", () => {

expect(page.root).toEqualHtml(`<h1 class="test">My Heading</h1>`);
});

it("should render a div", async () => {
const page = await newSpecPage({
components: [Dummy], // Required so we are feeding it a Dummy component
template: () => <Heading class="test">My Heading</Heading>
});

expect(page.root).toEqualHtml(`<div class="test">My Heading</div>`);
});
});
4 changes: 2 additions & 2 deletions src/components/functional/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { JSXBase } from "@stencil/core/internal";
export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;

interface HeadingProps extends JSXBase.HTMLAttributes {
level: HeadingLevel;
level?: HeadingLevel;
}

export function constrainHeadingLevel(level: number): HeadingLevel {
return Math.min(Math.max(Math.ceil(level), 1), 6) as HeadingLevel;
}

export const Heading: FunctionalComponent<HeadingProps> = (props, children) => {
const HeadingTag = `h${props.level}`;
const HeadingTag = props.level ? `h${props.level}` : "div";

delete props.level;

Expand Down
3 changes: 1 addition & 2 deletions src/components/list-item-group/list-item-group.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component, Element, Prop, h, VNode, Host } from "@stencil/core";
import { CSS } from "./resources";
import { HEADING_LEVEL } from "./resources";
import { HeadingLevel, Heading, constrainHeadingLevel } from "../functional/Heading";

/**
Expand Down Expand Up @@ -50,7 +49,7 @@ export class ListItemGroup {
"calcite-list, calcite-list-item-group"
)?.headingLevel;
const relativeLevel = parentLevel ? constrainHeadingLevel(parentLevel + 1) : null;
const level = headingLevel || relativeLevel || HEADING_LEVEL;
const level = headingLevel || relativeLevel;

return (
<Host>
Expand Down
2 changes: 0 additions & 2 deletions src/components/list-item-group/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ export const CSS = {
heading: "heading",
container: "container"
};

export const HEADING_LEVEL = 3;
4 changes: 2 additions & 2 deletions src/components/panel/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Fragment,
State
} from "@stencil/core";
import { CSS, HEADING_LEVEL, ICONS, SLOTS, TEXT } from "./resources";
import { CSS, ICONS, SLOTS, TEXT } from "./resources";
import { getElementDir, toAriaBoolean } from "../../utils/dom";
import { Scale } from "../interfaces";
import { HeadingLevel, Heading } from "../functional/Heading";
Expand Down Expand Up @@ -457,7 +457,7 @@ export class Panel implements InteractiveComponent {
renderHeaderContent(): VNode {
const { heading, headingLevel, summary, description, hasHeaderContent } = this;
const headingNode = heading ? (
<Heading class={CSS.heading} level={headingLevel || HEADING_LEVEL}>
<Heading class={CSS.heading} level={headingLevel}>
{heading}
</Heading>
) : null;
Expand Down
2 changes: 0 additions & 2 deletions src/components/panel/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,3 @@ export const TEXT = {
open: "Open",
options: "Options"
};

export const HEADING_LEVEL = 3;
3 changes: 1 addition & 2 deletions src/components/pick-list-group/pick-list-group.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component, Element, Prop, h, VNode, Fragment } from "@stencil/core";
import { CSS, SLOTS } from "./resources";
import { HEADING_LEVEL } from "./resources";
import { getSlotted } from "../../utils/dom";
import { HeadingLevel, Heading, constrainHeadingLevel } from "../functional/Heading";
import {
Expand Down Expand Up @@ -74,7 +73,7 @@ export class PickListGroup implements ConditionalSlotComponent {
const title = groupTitle;
const parentLevel = el.closest("calcite-pick-list")?.headingLevel;
const relativeLevel = parentLevel ? constrainHeadingLevel(parentLevel + 1) : null;
const level = headingLevel || relativeLevel || HEADING_LEVEL;
const level = headingLevel || relativeLevel;

return (
<Fragment>
Expand Down
2 changes: 0 additions & 2 deletions src/components/pick-list-group/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ export const CSS = {
export const SLOTS = {
parentItem: "parent-item"
};

export const HEADING_LEVEL = 3;
11 changes: 2 additions & 9 deletions src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ import {
h,
VNode
} from "@stencil/core";
import {
CSS,
ARIA_CONTROLS,
ARIA_EXPANDED,
HEADING_LEVEL,
TEXT,
defaultPopoverPlacement
} from "./resources";
import { CSS, ARIA_CONTROLS, ARIA_EXPANDED, TEXT, defaultPopoverPlacement } from "./resources";
import {
FloatingCSS,
OverlayPositioning,
Expand Down Expand Up @@ -514,7 +507,7 @@ export class Popover implements FloatingUIComponent, OpenCloseComponent {
renderHeader(): VNode {
const { heading, headingLevel } = this;
const headingNode = heading ? (
<Heading class={CSS.heading} level={headingLevel || HEADING_LEVEL}>
<Heading class={CSS.heading} level={headingLevel}>
{heading}
</Heading>
) : null;
Expand Down
2 changes: 0 additions & 2 deletions src/components/popover/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ export const TEXT = {
export const defaultPopoverPlacement = "auto";
export const ARIA_CONTROLS = "aria-controls";
export const ARIA_EXPANDED = "aria-expanded";

export const HEADING_LEVEL = 2;
2 changes: 0 additions & 2 deletions src/components/tip-manager/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,3 @@ export const TEXT = {
previous: "Previous",
next: "Next"
};

export const HEADING_LEVEL = 2;
4 changes: 2 additions & 2 deletions src/components/tip-manager/tip-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
h,
VNode
} from "@stencil/core";
import { CSS, ICONS, TEXT, HEADING_LEVEL } from "./resources";
import { CSS, ICONS, TEXT } from "./resources";
import { getElementDir, toAriaBoolean } from "../../utils/dom";
import { HeadingLevel, Heading } from "../functional/Heading";
import { createObserver } from "../../utils/observers";
Expand Down Expand Up @@ -288,7 +288,7 @@ export class TipManager {
tabIndex={0}
>
<header class={CSS.header}>
<Heading class={CSS.heading} level={headingLevel || HEADING_LEVEL}>
<Heading class={CSS.heading} level={headingLevel}>
{groupTitle}
</Heading>
<calcite-action
Expand Down
5 changes: 0 additions & 5 deletions src/components/tip/resources.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { HEADING_LEVEL as PARENT_HEADING_LEVEL } from "../tip-manager/resources";
import { HeadingLevel } from "../functional/Heading";

export const CSS = {
container: "container",
header: "header",
Expand All @@ -22,5 +19,3 @@ export const SLOTS = {
export const TEXT = {
close: "Close"
};

export const HEADING_LEVEL = (PARENT_HEADING_LEVEL + 1) as HeadingLevel;
4 changes: 2 additions & 2 deletions src/components/tip/tip.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Element, Event, EventEmitter, Prop, h, VNode, Fragment } from "@stencil/core";
import { CSS, ICONS, SLOTS, TEXT, HEADING_LEVEL } from "./resources";
import { CSS, ICONS, SLOTS, TEXT } from "./resources";
import { getSlotted } from "../../utils/dom";
import { HeadingLevel, Heading, constrainHeadingLevel } from "../functional/Heading";
import {
Expand Down Expand Up @@ -110,7 +110,7 @@ export class Tip implements ConditionalSlotComponent {
const { heading, headingLevel, el } = this;
const parentLevel = el.closest("calcite-tip-manager")?.headingLevel;
const relativeLevel = parentLevel ? constrainHeadingLevel(parentLevel + 1) : null;
const level = headingLevel || relativeLevel || HEADING_LEVEL;
const level = headingLevel || relativeLevel;

return heading ? (
<header class={CSS.header}>
Expand Down