Skip to content

Commit

Permalink
Merge pull request #927 from City-of-Helsinki/UHF-X_empty_ul_elements
Browse files Browse the repository at this point in the history
UHF-X: Check for list item count before rendering ul
  • Loading branch information
Arkkimaagi authored Mar 25, 2024
2 parents 0bc0a60 + 1eaaeaf commit b55513e
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 29 deletions.
2 changes: 1 addition & 1 deletion dist/js/district-and-project-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/health-station-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/job-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/linkedevents.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/maternity-and-child-health-clinic-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/news-archive.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/ploughing-schedule.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/school-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/js/react/common/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function CardItem({
}
</div>

{cardTags &&
{cardTags && cardTags.length > 0 &&
<div className="card__tags">
<Tags tags={cardTags} langAttribute={langAttribute} />
</div>
Expand Down
51 changes: 31 additions & 20 deletions src/js/react/common/SelectionsWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactNode, MouseEventHandler } from 'react';
import { ReactNode, MouseEventHandler, Children } from 'react';
import type { DateTime } from 'luxon';
import { Button, IconCross } from 'hds-react';

Expand All @@ -8,24 +8,35 @@ type SelectionsWrapperProps = {
children: ReactNode;
};

const SelectionsWrapper = ({ showClearButton, resetForm, children }: SelectionsWrapperProps) => (
<div className='hdbt-search__selections-wrapper'>
<ul className='hdbt-search__selections-container content-tags__tags'>
{children}
<li className='hdbt-search__clear-all'>
<Button
aria-hidden={!showClearButton}
className='hdbt-search__clear-all-button'
iconLeft={<IconCross className='hdbt-search__clear-all-icon' />}
onClick={resetForm}
style={showClearButton ? {} : { visibility: 'hidden' }}
variant='supplementary'
>
{Drupal.t('Clear selections', {}, { context: 'React search: clear selections' })}
</Button>
</li>
</ul>
</div>
);
const SelectionsWrapper = ({ showClearButton, resetForm, children }: SelectionsWrapperProps) =>
{
// hasContent checks for string and react children if there would be any content to render and does not render the ul container if there is none
const hasContent =
typeof children === 'string'
? children.trim().length > 0
: Children.toArray(children).some((child) => child !== false && child !== undefined);

return (
<div className='hdbt-search__selections-wrapper'>
{hasContent && (
<ul className='hdbt-search__selections-container content-tags__tags'>
{children}
<li className='hdbt-search__clear-all'>
<Button
aria-hidden={!showClearButton}
className='hdbt-search__clear-all-button'
iconLeft={<IconCross className='hdbt-search__clear-all-icon' />}
onClick={resetForm}
style={showClearButton ? {} : { visibility: 'hidden' }}
variant='supplementary'
>
{Drupal.t('Clear selections', {}, { context: 'React search: clear selections' })}
</Button>
</li>
</ul>
)}
</div>
);
};

export default SelectionsWrapper;

0 comments on commit b55513e

Please sign in to comment.