Skip to content

Commit

Permalink
[web] Render section title conditionally
Browse files Browse the repository at this point in the history
To avoid having empty <p> HTML nodes when description is not given.
  • Loading branch information
dgdavid committed Feb 22, 2024
1 parent e8896a5 commit 93c4d21
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions web/src/components/core/Section.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import React from "react";
import { Link } from "react-router-dom";
import { Icon } from '~/components/layout';
import { ValidationErrors } from "~/components/core";
import { If, ValidationErrors } from "~/components/core";

/**
* Renders children into an HTML section
Expand All @@ -48,7 +48,7 @@ import { ValidationErrors } from "~/components/core";
* @typedef { Object } SectionProps
* @property {string} [icon] - Name of the section icon. Not rendered if title is not provided.
* @property {string} [title] - The section title. If not given, aria-label must be provided.
* @property {string} [description] - A section description. Use only if really needed.
* @property {string|React.ReactElement} [description] - A section description. Use only if really needed.
* @property {string} [name] - The section name. Used to build the header id.
* @property {string} [path] - Path where the section links to.
* when user clicks on the title, used for opening a dialog.
Expand Down Expand Up @@ -86,13 +86,13 @@ export default function Section({
const iconName = loading ? "loading" : icon;
const headerIcon = iconName ? <Icon name={iconName} /> : null;
const headerText = !path?.trim() ? title : <Link to={path}>{title}</Link>;
const renderDescription = React.isValidElement(description) || description?.length > 0;

return (
<header>
<h2 id={headerId}>{headerIcon}<span>{headerText}</span></h2>
<p>{description}</p>
<If condition={renderDescription} then={<p>{description}</p>} />
</header>

);
};

Expand Down

0 comments on commit 93c4d21

Please sign in to comment.