Skip to content

Commit

Permalink
fix(limel-dialog): fix broken markup and resulting styling of the header
Browse files Browse the repository at this point in the history
The slot>header>h1-h6 structure is not supported by MDCDialog. Change to h2 only to support correct
styling by MDC.

BREAKING CHANGE: While backwards compatible in most cases, some functionality has been removed. If
the `heading`-attribute is not set, the text-content of anything injected into the header-slot is
copied and placed in the new h2-element. But any use of `<em>`, `<strong>`, or similar, will be
stripped. So will any `<a>` tags. But none of these should be used in a dialog-heading anyway.
  • Loading branch information
adrianschmidt committed Sep 10, 2019
1 parent 22bea52 commit 3050fe2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/components/dialog/dialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
@import "@lime-material/typography/mdc-typography";
@import "@lime-material/dialog/mdc-dialog";

slot[name="header"] {
display: none;
}

.mdc-dialog__surface {
max-height: 95vh;
width: 70rem;
Expand Down
20 changes: 14 additions & 6 deletions src/components/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import {
styleUrl: 'dialog.scss',
})
export class Dialog {
/**
* The heading for the dialog, if any.
*/
@Prop({ reflectToAttr: true })
public heading: string;

/**
* `true` if the dialog is open, `false` otherwise.
* Defaults to `false`.
Expand Down Expand Up @@ -71,12 +77,7 @@ export class Dialog {
>
<div class="mdc-dialog__container">
<div class="mdc-dialog__surface">
<header
class="mdc-dialog__title"
id={'limel-dialog-title-' + this.id}
>
<slot name="header" />
</header>
{this.renderHeading()}
<div
class="mdc-dialog__content"
id={'limel-dialog-content-' + this.id}
Expand Down Expand Up @@ -105,6 +106,13 @@ export class Dialog {
this.mdcDialog.close();
}
}

private renderHeading() {
if (this.heading) {
return <h2 class="mdc-dialog__title">{this.heading.trim()}</h2>;
}
return null;
}
}

function createRandomString() {
Expand Down

0 comments on commit 3050fe2

Please sign in to comment.