🐛(react) fix multi select menu opening

At first we had a simple bug were it was not possible to open the
menu by clicking on the label. This fix is a rework to consider
the select wrapper as the toggle button itself, which is what we
do on the mono version. This change caused various tests to fail.
This commit is contained in:
Nathan Vasse
2024-01-31 17:55:41 +01:00
committed by NathanVss
parent 1445f4a222
commit d61ab65d82
6 changed files with 16 additions and 13 deletions

View File

@@ -87,7 +87,6 @@ export const SelectMonoAux = ({
}: SelectAuxProps) => {
const { t } = useCunningham();
const labelProps = downshiftReturn.getLabelProps();
return (
<Field state={state} {...props}>
<div

View File

@@ -63,6 +63,10 @@ export interface SelectMultiAuxProps extends SubProps {
export const SelectMultiAux = ({ children, ...props }: SelectMultiAuxProps) => {
const { t } = useCunningham();
const labelProps = props.downshiftReturn.getLabelProps();
// We need to remove onBlur from toggleButtonProps because it triggers a menu closing each time
// we tick a checkbox using the monoline style.
const { onBlur, ...toggleProps } = props.downshiftReturn.toggleButtonProps;
return (
<Field {...props}>
<div
@@ -85,6 +89,7 @@ export const SelectMultiAux = ({ children, ...props }: SelectMultiAuxProps) => {
props.downshiftReturn.isOpen && !props.disabled,
})}
{...props.downshiftReturn.wrapperProps}
{...toggleProps}
>
{props.selectedItems.map((selectedItem, index) => (
<input
@@ -138,7 +143,6 @@ export const SelectMultiAux = ({ children, ...props }: SelectMultiAuxProps) => {
</span>
}
disabled={props.disabled}
{...props.downshiftReturn.toggleButtonProps}
/>
</div>
<div className="c__select__inner__value">

View File

@@ -155,6 +155,7 @@ export const SelectMultiSearchable = forwardRef<SelectHandle, SubProps>(
{...inputProps}
onFocus={() => {
setHasInputFocused(true);
downshiftReturn.openMenu();
}}
onBlur={() => {
setHasInputFocused(false);

View File

@@ -115,13 +115,6 @@ export const SelectMultiSimple = forwardRef<SelectHandle, SubProps>(
menuOptionsStyle={props.monoline ? "checkbox" : "plain"}
downshiftReturn={{
...downshiftReturn,
wrapperProps: {
onClick: () => {
if (!props.disabled) {
downshiftReturn.toggleMenu();
}
},
},
toggleButtonProps: downshiftReturn.getToggleButtonProps({
...useMultipleSelectionReturn.getDropdownProps({
preventKeyAction: downshiftReturn.isOpen,

View File

@@ -781,8 +781,11 @@ describe("<Select multi={true} />", () => {
await user.click(clearButton);
expectSelectedOptions([]);
// Select again London.
// Close and re-open the menu. ( This is needed in this tests but in real life it works, I don't know exactly why .. )
await user.click(input);
await user.click(input);
// Select again Paris.
await user.click(
screen.getByRole("option", {
name: "Paris",
@@ -830,7 +833,7 @@ describe("<Select multi={true} />", () => {
// Focus the select.
await user.click(input);
expectMenuToBeOpen(menu);
expect(document.activeElement?.className).toContain("c__button");
expect(document.activeElement?.className).toContain("c__select__wrapper");
// Blur the select.
ref.current?.blur();
@@ -1041,8 +1044,6 @@ describe("<Select multi={true} />", () => {
// Make sure the option is selected.
expectSelectedOptionsText(["London", "Paris"]);
screen.logTestingPlaygroundURL();
// Make sure the menu stays open.
expectMenuToBeOpen(menu);