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: d2l-collapsible-panel > support h5 and h6 semantic levels #3762

Merged
merged 10 commits into from
Jun 21, 2023

Conversation

jameswklassen
Copy link
Contributor

@jameswklassen jameswklassen commented Jun 20, 2023

Description

There are use cases that require semantic h5 and h6 elements for the panel title. There are no heading styles beyond h4, but the semantic elements can still be supported.

If a h5 or h6 is selected, it will default to use the h4 styles. Consumers can still override styles, like before.

Closes #3761

@github-actions
Copy link
Contributor

Thanks for the PR! 🎉

We've deployed an automatic preview for this PR - you can see your changes here:

URL https://pr-3762-brightspace-ui-core.d2l.dev/

Note
The build needs to finish before your changes are deployed.
Changes to the PR will automatically update the instance.

@github-actions
Copy link
Contributor

Visual diff tests failed - pull request #3763 has been opened with the updated goldens.

@jameswklassen jameswklassen marked this pull request as ready for review June 20, 2023 22:02
@jameswklassen jameswklassen requested a review from a team as a code owner June 20, 2023 22:02
Comment on lines 462 to 468
const headingStyle = (this.headingStyle === defaultHeading && this.headingLevel !== this.headingStyle) ? this.headingLevel : this.headingStyle;
this.headingStyle = normalizeHeadingStyle(headingStyle);

const titleClasses = {
'd2l-collapsible-panel-title': true,
'd2l-skeletize': true,
[`d2l-heading-${headingStyle}`]: true,
[`d2l-heading-${this.headingStyle}`]: true,
Copy link
Contributor Author

@jameswklassen jameswklassen Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that heading-style was appearing in the DOM as the default "3", regardless of what the component did, since we never update this.headingStyle.

Figured it made sense to update the property here...shouldn't change any functionality.

let headingStyle = (this.headingStyle === defaultHeading && this.headingLevel !== this.headingStyle) ? this.headingLevel : this.headingStyle;
headingStyle = normalizeHeadingNumber(headingStyle);
const headingStyle = (this.headingStyle === defaultHeading && this.headingLevel !== this.headingStyle) ? this.headingLevel : this.headingStyle;
this.headingStyle = normalizeHeadingStyle(headingStyle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love mutating the property here, since if the normalization did something it's going to cause a re-render (and we're already in render()).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good point...I forgot why we did it this way.

That said, I'm not crazy about having an incorrect heading-style attribute on the DOM element...maybe the normalization would make more sense in updated? Then we just use this.headingStyle and this.headingLevel directly in this render method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too worried about it, but if you want to ensure that it's always valid I'd suggest creating a getter/setter and doing the validation in the setter. Here's an example from color input.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason the get/set method is better than updated is because updated still happens after render, so 1) the value will be invalid inside render() and 2) "fixing" it will trigger a second render.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely agree.

Also, for cases where we need to compute an internal reactive property in advance of render(), we have willUpdate(...). It's rarely used in core, partly because a lot of the components were written before it existed. There's probably a few cases where we could avoid double rendering by using it. Anyway, just something to keep in mind.

@jameswklassen jameswklassen marked this pull request as draft June 21, 2023 12:59
Copy link
Member

@dlockhart dlockhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@github-actions
Copy link
Contributor

Visual diff tests failed - pull request #3767 has been opened with the updated goldens.

@github-actions
Copy link
Contributor

Visual diff tests failed - pull request #3768 has been opened with the updated goldens.

@jameswklassen jameswklassen marked this pull request as ready for review June 21, 2023 15:46
@jameswklassen jameswklassen merged commit 82302d0 into main Jun 21, 2023
@jameswklassen jameswklassen deleted the jwk/collapsible-panel-h5-h6 branch June 21, 2023 17:43
@ghost
Copy link

ghost commented Jun 21, 2023

🎉 This PR is included in version 2.131.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

collapsible-panel: Support heading level 5 and 6
3 participants