Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,6 @@ describe("AutocompleteRebuilt", () => {
<InputText
ref={inputRef}
{...inputProps}
version={2}
// Compose with internal onChange so Autocomplete behavior still works
onChange={(val, evt) => {
inputProps.onChange?.(val, evt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { useChipNavigation } from "./hooks/useChipNavigation";
import { preventDefaultPointerDown } from "./utils/interactionUtils";
import { FloatingMenu } from "./components/FloatingMenu";
import { InputText } from "../InputText";
import type { InputTextRebuiltProps } from "../InputText/InputText.types";
import type { InputTextProps } from "../InputText/InputText.types";
import { FormFieldWrapper } from "../FormField";
import { mergeRefs } from "../utils/mergeRefs";
import { filterDataAttributes } from "../sharedHelpers/filterDataAttributes";
Expand Down Expand Up @@ -154,8 +154,7 @@ function AutocompleteRebuiltInternal<
: undefined,
};

const inputProps: InputTextRebuiltProps = {
version: 2 as const,
const inputProps: InputTextProps = {
value: inputValue,
onChange: props.readOnly ? undefined : onInputChangeFromUser,
// Ensure focus/blur callbacks still fire in readOnly mode where we don't spread getReferenceProps
Expand Down
5 changes: 2 additions & 3 deletions packages/components/src/Autocomplete/Autocomplete.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import type { AnyOption, CustomOptionsMenuProp } from ".";
import { Autocomplete } from ".";
import type { InputTextRef } from "../InputText";
import { Text } from "../Text";

function returnOptions(options: AnyOption[]) {
Expand Down Expand Up @@ -245,7 +244,7 @@ describe("Autocomplete", () => {
it("should focus input text", async () => {
const placeholder = "Got milk?";

const textRef = React.createRef<InputTextRef>();
const textRef = React.createRef<HTMLInputElement>();

render(
<Autocomplete
Expand All @@ -271,7 +270,7 @@ describe("Autocomplete", () => {

const placeholder = "Got milk?";

const textRef = React.createRef<InputTextRef>();
const textRef = React.createRef<HTMLInputElement>();

render(
<Autocomplete
Expand Down
13 changes: 6 additions & 7 deletions packages/components/src/Autocomplete/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
type Option,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: we should remove v1 Autocomplete implementation and ship that before this InputText PR.

Then we can delete the changes here.

} from "./Autocomplete.types";
import { isOptionGroup } from "./Autocomplete.utils";
import type { InputTextRef } from "../InputText";
import { InputText } from "../InputText";
import { mergeRefs } from "../utils/mergeRefs";

Expand All @@ -32,16 +31,17 @@ function AutocompleteInternal<
placeholder,
onBlur,
onFocus,
validations,
customRenderMenu,
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Exclude this from inputProps
version,
...inputProps
}: // eslint-disable-next-line import/no-deprecated
AutocompleteLegacyProps<
GenericOption,
GenericOptionValue,
GenericGetOptionsValue
>,
ref: Ref<InputTextRef>,
ref: Ref<HTMLInputElement>,
) {
const initialOptionsMemo = useMemo(
() => mapToOptions(initialOptions),
Expand All @@ -55,7 +55,7 @@ function AutocompleteInternal<
null,
);
const delayedSearch = useDebounce(updateSearch, debounceRate);
const inputRef = useRef<InputTextRef | null>(null);
const inputRef = useRef<HTMLInputElement | null>(null);

useEffect(() => {
delayedSearch();
Expand All @@ -69,14 +69,13 @@ function AutocompleteInternal<
<div className={styles.autocomplete} ref={setAutocompleteRef}>
<InputText
ref={mergeRefs([ref, inputRef])}
autocomplete={false}
autoComplete="off"
size={size}
value={inputText}
onChange={handleInputChange}
placeholder={placeholder}
onFocus={handleInputFocus}
onBlur={handleInputBlur}
validations={validations}
{...inputProps}
/>
<Menu
Expand Down Expand Up @@ -169,5 +168,5 @@ export const Autocomplete = forwardRef(AutocompleteInternal) as <
GenericOptionValue,
GenericGetOptionsValue
> &
RefAttributes<InputTextRef>,
RefAttributes<HTMLInputElement>,
) => ReturnType<typeof AutocompleteInternal>;
16 changes: 4 additions & 12 deletions packages/components/src/Autocomplete/Autocomplete.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
RebuiltInputCommonProps,
} from "../sharedHelpers/types";
import type { FormFieldProps } from "../FormField";
import type { InputTextRebuiltProps, InputTextRef } from "../InputText";
import type { InputTextProps } from "../InputText";

/**
* ARIA attributes for Autocomplete with managed/orchestrated behavior.
Expand Down Expand Up @@ -165,11 +165,6 @@ export interface AutocompleteLegacyProps<
) =>
| Array<GenericGetOptionsValue | GenericOption>
| Promise<Array<GenericGetOptionsValue | GenericOption>>;

/**
* Validations to run on the input.
*/
readonly validations?: FormFieldProps["validations"];
}

// For backward compatibility
Expand Down Expand Up @@ -201,7 +196,7 @@ export interface MenuProps<
/**
* Ref to the TextInput element.
*/
readonly inputRef: RefObject<InputTextRef | null>;
readonly inputRef: RefObject<HTMLInputElement | null>;
onOptionSelect(chosenOption?: GenericOptionValue): void;
readonly customRenderMenu?: (
props: CustomOptionsMenuProp<GenericOption, GenericOptionValue>,
Expand Down Expand Up @@ -235,11 +230,8 @@ export interface CustomOptionsMenuProp<

/**
* Ref to the TextInput element.
* v1 provides InputTextRef; v2 provides a DOM element ref.
*/
readonly inputRef: RefObject<
InputTextRef | HTMLInputElement | HTMLTextAreaElement | null
>;
readonly inputRef: RefObject<HTMLInputElement | HTMLTextAreaElement | null>;
/**
* Component that wraps the menu content. Used for handling keyboard scroll behavior.
*/
Expand Down Expand Up @@ -517,7 +509,7 @@ interface AutocompleteRebuiltBaseProps<
*/
readonly customRenderInput?: (props: {
inputRef: Ref<HTMLInputElement | HTMLTextAreaElement>;
inputProps: InputTextRebuiltProps;
inputProps: InputTextProps;
}) => React.ReactNode;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,7 @@ const TemplateEmptyStateAndActions = () => {
<Modal open={modalOpen} onRequestClose={() => setModalOpen(false)}>
<Content>
<Heading level={4}>Create service</Heading>
<InputText
value={serviceValue}
onChange={(val: string) => setServiceValue(val)}
/>
<InputText value={serviceValue} onChange={setServiceValue} />
<Button label="Create" onClick={() => setModalOpen(false)} />
</Content>
</Modal>
Expand Down Expand Up @@ -761,6 +758,7 @@ const TemplateFocusBehavior = () => {
const [lastFocus, setLastFocus] = useState("");

const [openCreatModal, setOpenCreatModal] = useState(false);
const [serviceNameValue, setServiceNameValue] = useState("");

const emptyActions: {
type: "action";
Expand Down Expand Up @@ -789,7 +787,6 @@ const TemplateFocusBehavior = () => {
</Text>
<InputText
placeholder="Another Field to Tab From (Not an Autocomplete)"
version={2}
value={otherInputValue}
onChange={setOtherInputValue}
onBlur={() => setLastBlur("First InputText blurred")}
Expand All @@ -811,7 +808,6 @@ const TemplateFocusBehavior = () => {
])}
/>
<InputText
version={2}
placeholder="Another Field to Tab To and From (Not an Autocomplete)"
value={anotherInputValue}
onChange={setAnotherInputValue}
Expand Down Expand Up @@ -839,7 +835,11 @@ const TemplateFocusBehavior = () => {
>
<Content>
<Heading level={4}>Create service</Heading>
<InputText placeholder="Service name" />
<InputText
placeholder="Service name"
value={serviceNameValue}
onChange={setServiceNameValue}
/>
<Button label="Create" onClick={() => setOpenCreatModal(false)} />
</Content>
</Modal>
Expand Down
3 changes: 1 addition & 2 deletions packages/components/src/Autocomplete/Menu/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { RefObject } from "react";
import React from "react";
import type { InputTextRef } from "@jobber/components/InputText";
import type { DefaultMenuProps } from "./DefaultMenu";
import { DefaultMenu } from "./DefaultMenu";
import { useAutocompleteMenu } from "./MenuWrapper";
Expand Down Expand Up @@ -57,7 +56,7 @@ interface InternalCustomMenuProps<
readonly options: GenericOption[];
readonly selectedOption?: GenericOptionValue;
readonly attachTo: MenuProps["attachTo"];
readonly inputRef: RefObject<InputTextRef | null>;
readonly inputRef: RefObject<HTMLInputElement | null>;
readonly onOptionSelect: (chosenOption?: GenericOptionValue) => void;
readonly customRenderMenu: (
props: CustomOptionsMenuProp<GenericOption, GenericOptionValue>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports[`Autocomplete renders an Autocomplete 1`] = `
autocomplete="off"
class="input"
id="«r0»"
type="text"
name="generatedName--«r0»"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be expected. type="text" is the default input type when not supplied. The v2 implementation just doesn't set it.

value=""
/>
</div>
Expand Down Expand Up @@ -76,7 +76,7 @@ exports[`Autocomplete should display headers when headers are passed in 1`] = `
autocomplete="off"
class="input"
id="«r5»"
type="text"
name="generatedName--«r5»"
value=""
/>
</div>
Expand Down
11 changes: 6 additions & 5 deletions packages/components/src/Autocomplete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {
} from "./Autocomplete.types";
import { AutocompleteRebuilt } from "./Autocomplete.rebuilt";
import { Autocomplete as AutocompleteLegacy } from "./Autocomplete";
import type { InputTextRef } from "../InputText";

export type { OptionLike } from "./Autocomplete.types";

Expand Down Expand Up @@ -75,7 +74,7 @@ function isNewAutocompleteProps(

function AutocompleteShim(
props: AutocompleteShimProps,
ref: React.Ref<InputTextRef | HTMLInputElement | HTMLTextAreaElement>,
ref: React.Ref<HTMLInputElement | HTMLTextAreaElement>,
) {
if (isNewAutocompleteProps(props)) {
return (
Expand All @@ -86,7 +85,9 @@ function AutocompleteShim(
);
}

return <AutocompleteLegacy {...props} ref={ref as React.Ref<InputTextRef>} />;
return (
<AutocompleteLegacy {...props} ref={ref as React.Ref<HTMLInputElement>} />
);
}

const AutocompleteForwarded = forwardRef(AutocompleteShim);
Expand Down Expand Up @@ -121,7 +122,7 @@ export const Autocomplete = AutocompleteForwarded as {
GenericGetOptionsValue
> & {
version?: 1;
ref?: React.Ref<InputTextRef>;
ref?: React.Ref<HTMLInputElement>;
// Disallow v2-only props for clearer DX
menu?: never;
},
Expand All @@ -131,7 +132,7 @@ export const Autocomplete = AutocompleteForwarded as {
// eslint-disable-next-line import/no-deprecated
props: AutocompleteLegacyProps & {
version?: 1;
ref?: React.Ref<InputTextRef>;
ref?: React.Ref<HTMLInputElement>;
// Disallow v2-only props for clearer DX
menu?: never;
},
Expand Down
Loading