Merge pull request #6809 from tchak/fix-multiselect-menu

Fix multiselect menu
This commit is contained in:
Paul Chavard 2022-01-11 14:10:40 +01:00 committed by GitHub
commit 905c442d3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 7 deletions

View file

@ -535,6 +535,13 @@
padding: $default-spacer;
}
[data-reach-combobox-no-results] {
font-size: 16px;
color: $dark-grey;
background: $light-grey;
padding: $default-spacer;
}
[data-reach-combobox-token] button {
cursor: pointer;
background-color: transparent;

View file

@ -116,6 +116,7 @@ function ComboMultiple({
}
setTerm('');
awaitFormSubmit.done();
hidePopover();
};
const onRemove = (label) => {
@ -148,6 +149,18 @@ function ComboMultiple({
}
};
const hidePopover = () => {
document
.querySelector(`[data-reach-combobox-popover-id="${inputId}"]`)
?.setAttribute('hidden', 'true');
};
const showPopover = () => {
document
.querySelector(`[data-reach-combobox-popover-id="${inputId}"]`)
?.removeAttribute('hidden');
};
const onBlur = () => {
if (
term &&
@ -156,6 +169,10 @@ function ComboMultiple({
awaitFormSubmit(() => {
onSelect(term);
});
} else {
setTimeout(() => {
hidePopover();
}, 200);
}
};
@ -185,6 +202,7 @@ function ComboMultiple({
onChange={handleChange}
onKeyDown={onKeyDown}
onBlur={onBlur}
onClick={showPopover}
autocomplete={false}
id={inputId}
aria-label={label}
@ -195,14 +213,25 @@ function ComboMultiple({
/>
</ComboboxTokenLabel>
{results && (results.length > 0 || !acceptNewValues) && (
<ComboboxPopover className="shadow-popup">
{results.length === 0 && (
<p>
Aucun résultat{' '}
<button onClick={() => setTerm('')}>Effacer</button>
</p>
)}
<ComboboxPopover
className="shadow-popup"
data-reach-combobox-popover-id={inputId}
>
<ComboboxList>
{results.length === 0 && (
<li data-reach-combobox-no-results>
Aucun résultat{' '}
<button
onClick={() => {
setTerm('');
inputRef.current?.focus();
}}
className="button"
>
Effacer
</button>
</li>
)}
{results.map(([label, value], index) => {
if (label.startsWith('--')) {
return <ComboboxSeparator key={index} value={label} />;