🐛(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:
5
.changeset/eighty-teachers-collect.md
Normal file
5
.changeset/eighty-teachers-collect.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@openfun/cunningham-react": patch
|
||||
---
|
||||
|
||||
fix multi select menu opening
|
||||
@@ -87,7 +87,6 @@ export const SelectMonoAux = ({
|
||||
}: SelectAuxProps) => {
|
||||
const { t } = useCunningham();
|
||||
const labelProps = downshiftReturn.getLabelProps();
|
||||
|
||||
return (
|
||||
<Field state={state} {...props}>
|
||||
<div
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -155,6 +155,7 @@ export const SelectMultiSearchable = forwardRef<SelectHandle, SubProps>(
|
||||
{...inputProps}
|
||||
onFocus={() => {
|
||||
setHasInputFocused(true);
|
||||
downshiftReturn.openMenu();
|
||||
}}
|
||||
onBlur={() => {
|
||||
setHasInputFocused(false);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user