Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8a72d3a
export typeahead utils
Michele-Masciave Apr 11, 2025
f8dc2b0
integrate placeholder fix and changelog
Michele-Masciave Apr 16, 2025
a857384
adjust typescript
Michele-Masciave Apr 16, 2025
e1267ef
prepare-pr
Michele-Masciave Apr 28, 2025
12211f1
fixed
Michele-Masciave Apr 30, 2025
92e5c21
Merge branch 'main' of https://github.com/Michele-Masciave/react-hook…
Michele-Masciave Apr 30, 2025
a9347da
Merge branch 'neolution-ch:main' into main
Michele-Masciave May 7, 2025
2987413
Merge branch 'neolution-ch:main' into main
Michele-Masciave Jun 3, 2025
acad69e
Merge branch 'main' of https://github.com/Michele-Masciave/react-hook…
Michele-Masciave Jun 13, 2025
de96e5c
Merge branch 'neolution-ch:main' into main
Michele-Masciave Jun 18, 2025
fbfcc8e
Merge branch 'neolution-ch:main' into main
Michele-Masciave Jun 25, 2025
b5c2533
Merge branch 'main' of https://github.com/Michele-Masciave/react-hook…
Michele-Masciave Jul 7, 2025
7843d38
Merge branch 'neolution-ch:main' into main
Michele-Masciave Jul 16, 2025
6b81771
Merge branch 'neolution-ch:main' into main
Michele-Masciave Sep 26, 2025
743acf1
Merge branch 'neolution-ch:main' into main
Michele-Masciave Sep 29, 2025
022db3c
Merge branch 'neolution-ch:main' into main
Michele-Masciave Oct 1, 2025
bbd78a7
Merge branch 'neolution-ch:main' into main
Michele-Masciave Oct 21, 2025
5d28ea3
Merge branch 'neolution-ch:main' into main
Michele-Masciave Dec 3, 2025
3e9f9a7
Merge branch 'neolution-ch:main' into main
Michele-Masciave Dec 10, 2025
814c18e
Merge branch 'neolution-ch:main' into main
Michele-Masciave Dec 15, 2025
a2108d9
Merge branch 'neolution-ch:main' into main
Michele-Masciave Jan 8, 2026
349cd68
Merge branch 'neolution-ch:main' into main
Michele-Masciave Jan 13, 2026
d2e3498
solution
Michele-Masciave Feb 5, 2026
ff3a6f3
solution #2
Michele-Masciave Feb 5, 2026
513fda5
fix test
Michele-Masciave Feb 5, 2026
d20b103
prettier
Michele-Masciave Feb 5, 2026
650b43d
export also TypeaheadFitMenuPopper
Michele-Masciave Feb 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- support to allow menu size to fit the longest option into `StaticTypeahead` and `AsyncTypeahead`, via `fitMenuContent`.

## [3.15.1] - 2026-01-12

### Fix
Expand Down
37 changes: 36 additions & 1 deletion cypress/cypress/component/Typeahead/AsyncTypeaheadInput.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,6 @@ it("works with fixed options excluded", () => {
});

it("innerRef works correctly", () => {
const { simpleOptions } = generateOptions();
const name = faker.random.alpha(10);
const options = generateOptions();

Expand Down Expand Up @@ -964,3 +963,39 @@ it("innerRef works correctly", () => {
cy.get("button[title=focus]").click();
cy.get(`#${name}`).should("be.focused");
});

it("works with fitContentMenu", () => {
const name = faker.random.alpha(10);
const specificOptions = [
{ label: "A Very Long Movie Title That Exceeds Normal Lengths", value: "1" },
{ label: "The Lord of the Rings: The Return of the King", value: "2" },
];

cy.mount(
<div className="p-4">
<Form
onSubmit={() => {
// Nothing to do
}}
>
<AsyncTypeaheadInput
style={{ width: 300 }}
queryFn={async (query: string) => await fetchMock(specificOptions, query, true)}
name={name}
label={name}
fitMenuContent
/>
</Form>
</div>,
);

cy.get(`#${name}`).click();
cy.focused().type(specificOptions[0].label);
cy.get(".MuiInputBase-root").should("have.css", "width", "300px");
cy.get("div[role='presentation']").should(($div) => {
const popperWidth = $div.width() ?? 0;
const paperWidth = $div.find("div.MuiPaper-root").width() ?? 0;
expect(paperWidth).to.be.equal(popperWidth);
expect(popperWidth).to.be.greaterThan(300);
});
});
34 changes: 34 additions & 0 deletions cypress/cypress/component/Typeahead/StaticTypeaheadInput.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -621,3 +621,37 @@ it("innerRef works correctly", () => {
cy.get("button[title=focus]").click();
cy.get(`#${name}`).should("be.focused");
});

it("works with fitContentMenu", () => {
const { simpleOptions } = generateOptions();
const name = faker.random.alpha(10);
const specificOptions = ["A Very Long Movie Title That Exceeds Normal Lengths", "The Lord of the Rings: The Return of the King"];

cy.mount(
<div className="p-4">
<Form
onSubmit={() => {
// Nothing to do
}}
>
<StaticTypeaheadInput
style={{ width: 300 }}
multiple
name={name}
label={name}
options={[...specificOptions, ...simpleOptions]}
fitMenuContent
/>
</Form>
</div>,
);

cy.get(`#${name}`).click();
cy.get(".MuiInputBase-root").should("have.css", "width", "300px");
cy.get("div[role='presentation']").should(($div) => {
const popperWidth = $div.width() ?? 0;
const paperWidth = $div.find("div.MuiPaper-root").width() ?? 0;
expect(paperWidth).to.be.equal(popperWidth);
expect(popperWidth).to.be.greaterThan(300);
});
});
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from "./lib/types/Form";
export * from "./lib/DatePickerInput";
export * from "./lib/ColorPickerInput";
export * from "./lib/RatingInput";
export * from "./lib/components/Typeahead/TypeaheadFitMenuPopper";
export * from "./lib/helpers/dateUtils";
export * from "./lib/helpers/form";
export * from "./lib/helpers/mui";
Expand Down
6 changes: 6 additions & 0 deletions src/lib/AsyncTypeaheadInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useFormContext } from "./context/FormContext";
import { TypeaheadTextField } from "./components/Typeahead/TypeaheadTextField";
import { FormGroupLayout } from "./FormGroupLayout";
import { LabelValueOption } from "./types/LabelValueOption";
import { TypeaheadFitMenuPopper } from "./components/Typeahead/TypeaheadFitMenuPopper";

interface AsyncTypeaheadInputRef {
resetValues: () => void;
Expand Down Expand Up @@ -75,6 +76,7 @@ const AsyncTypeaheadInput = <T extends FieldValues>(props: AsyncTypeaheadInputPr
autocompleteProps,
fixedOptions,
withFixedOptionsInValue = true,
fitMenuContent,
} = props;

const [options, setOptions] = useState<TypeaheadOptions>(defaultOptions);
Expand Down Expand Up @@ -145,6 +147,10 @@ const AsyncTypeaheadInput = <T extends FieldValues>(props: AsyncTypeaheadInputPr
<Autocomplete<TypeaheadOption, boolean, boolean, boolean>
{...autocompleteProps}
{...field}
slots={{
popper: fitMenuContent ? TypeaheadFitMenuPopper : undefined,
...autocompleteProps?.slots,
}}
id={id}
multiple={multiple}
loading={isLoading}
Expand Down
6 changes: 6 additions & 0 deletions src/lib/StaticTypeaheadInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import { TypeaheadTextField } from "./components/Typeahead/TypeaheadTextField";
import { FormGroupLayout } from "./FormGroupLayout";
import { LabelValueOption } from "./types/LabelValueOption";
import { TypeaheadFitMenuPopper } from "./components/Typeahead/TypeaheadFitMenuPopper";

interface StaticTypeaheadInputProps<T extends FieldValues> extends CommonTypeaheadProps<T> {
options: TypeaheadOptions;
Expand Down Expand Up @@ -66,6 +67,7 @@ const StaticTypeaheadInput = <T extends FieldValues>(props: StaticTypeaheadInput
fixedOptions,
withFixedOptionsInValue = true,
innerRef,
fitMenuContent,
} = props;

const [page, setPage] = useState(1);
Expand Down Expand Up @@ -118,6 +120,10 @@ const StaticTypeaheadInput = <T extends FieldValues>(props: StaticTypeaheadInput
<Autocomplete<TypeaheadOption, boolean, boolean, boolean>
{...autocompleteProps}
{...field}
slots={{
popper: fitMenuContent ? TypeaheadFitMenuPopper : undefined,
...autocompleteProps?.slots,
}}
id={id}
multiple={multiple}
groupBy={useGroupBy ? groupOptions : undefined}
Expand Down
20 changes: 20 additions & 0 deletions src/lib/components/Typeahead/TypeaheadFitMenuPopper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Popper, { PopperProps } from "@mui/material/Popper";

const TypeaheadFitMenuPopper = (props: PopperProps) => {
const { anchorEl } = props;

return (
<Popper
{...props}
style={{
// ensure popper is at least as wide as the input field
minWidth: (anchorEl as HTMLElement)?.clientWidth,
// ensure popper fits the longest option width
width: "fit-content",
}}
placement="bottom-start"
/>
);
};

export { TypeaheadFitMenuPopper };
1 change: 1 addition & 0 deletions src/lib/types/Typeahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface CommonTypeaheadProps<T extends FieldValues>
fixedOptions?: TypeaheadOptions;
withFixedOptionsInValue?: boolean;
innerRef?: MutableRefObject<HTMLInputElement | null>;
fitMenuContent?: boolean;
getOptionDisabled?: (option: TypeaheadOption) => boolean;
onChange?: (selected: string | string[]) => void;
onInputChange?: (text: string, reason: AutocompleteInputChangeReason) => void;
Expand Down
Loading