Skip to content

Commit

Permalink
fix: dropdown checkbox click area (#1215)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Aug 17, 2024
1 parent 95ac098 commit f370b56
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 42 deletions.
21 changes: 11 additions & 10 deletions src/search-manager/FilterByBlockType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,17 @@ const FilterByBlockType: React.FC<Record<never, never>> = () => {
<Menu className="block-type-refinement-menu" style={{ boxShadow: 'none' }}>
{
Object.entries(sortedBlockTypes).map(([blockType, count]) => (
<MenuItem
key={blockType}
as={Form.Checkbox}
value={blockType}
checked={blockTypesFilter.includes(blockType)}
onChange={handleCheckboxChange}
>
<BlockTypeLabel type={blockType} />{' '}
<Badge variant="light" pill>{count}</Badge>
</MenuItem>
<label key={blockType} className="d-inline">
<MenuItem
as={Form.Checkbox}
value={blockType}
checked={blockTypesFilter.includes(blockType)}
onChange={handleCheckboxChange}
>
<BlockTypeLabel type={blockType} />{' '}
<Badge variant="light" pill>{count}</Badge>
</MenuItem>
</label>
))
}
{
Expand Down
68 changes: 36 additions & 32 deletions src/search-manager/FilterByTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,43 @@ const TagMenuItem: React.FC<{
const randomNumber = React.useMemo(() => Math.floor(Math.random() * 1000), []);
const checkboxId = tagPath.replace(/[\W]/g, '_') + randomNumber;

const expandChildrenClick = React.useCallback((e) => {
e.preventDefault();
onToggleChildren?.(tagPath);
}, [onToggleChildren, tagPath]);

return (
<div className="pgn__menu-item pgn__form-checkbox tag-toggle-item" role="group">
<input
type="checkbox"
id={checkboxId}
checked={isChecked}
onChange={onClickCheckbox}
className="pgn__form-checkbox-input flex-shrink-0"
/>
<label htmlFor={checkboxId} className="flex-shrink-1 mb-0">
{label}{' '}
<Badge variant="light" pill>{tagCount}</Badge>
</label>
{
hasChildren
? (
<IconButton
src={isExpanded ? ArrowDropUp : ArrowDropDown}
iconAs={Icon}
alt={
intl.formatMessage(
isExpanded ? messages.childTagsCollapse : messages.childTagsExpand,
{ tagName: label },
)
}
onClick={() => onToggleChildren?.(tagPath)}
variant="primary"
size="sm"
/>
) : null
}
</div>
<label className="d-inline">
<div className="pgn__menu-item pgn__form-checkbox tag-toggle-item" role="group">
<input
type="checkbox"
id={checkboxId}
checked={isChecked}
onChange={onClickCheckbox}
className="pgn__form-checkbox-input flex-shrink-0"
/>
{label}
<Badge variant="light" pill className="ml-1">{tagCount}</Badge>
{
hasChildren
? (
<IconButton
src={isExpanded ? ArrowDropUp : ArrowDropDown}
iconAs={Icon}
alt={
intl.formatMessage(
isExpanded ? messages.childTagsCollapse : messages.childTagsExpand,
{ tagName: label },
)
}
onClick={expandChildrenClick}
variant="primary"
size="sm"
/>
) : null
}
</div>
</label>
);
};

Expand Down Expand Up @@ -125,7 +130,6 @@ const TagOptions: React.FC<{
return (
<React.Fragment key={tagName}>
<TagMenuItem
key={tagName}
label={tagName}
tagCount={t.tagCount}
tagPath={tagPath}
Expand Down

0 comments on commit f370b56

Please sign in to comment.