Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Select and SearchField, take 2 #2142

Merged
merged 8 commits into from
Feb 21, 2024
22 changes: 12 additions & 10 deletions packages/odyssey-react-mui/src/SearchField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ import {

import { CloseCircleFilledIcon, SearchIcon } from "./icons.generated";
import { Field } from "./Field";
import {
FieldComponentProps,
FieldComponentRenderProps,
} from "./FieldComponentProps";
import { FieldComponentProps } from "./FieldComponentProps";
import type { HtmlProps } from "./HtmlProps";
import { getControlState, useInputValues } from "./inputUtils";

export const searchVariantValues = ["outline", "filled"] as const;

export type SearchFieldProps = {
/**
* This prop helps users to fill forms faster, especially on mobile devices.
Expand Down Expand Up @@ -84,17 +83,16 @@ export type SearchFieldProps = {
* The value of the `input` element, to use when controlled.
*/
value?: string;
/**
* Whether the SearchField has a gray or white background
*/
variant?: (typeof searchVariantValues)[number];
} & Pick<
FieldComponentProps,
"ariaDescribedBy" | "id" | "isDisabled" | "name" | "isFullWidth"
> &
HtmlProps;

type FieldRenderProps = Partial<
Pick<FieldComponentRenderProps, "ariaDescribedBy">
> &
Pick<FieldComponentRenderProps, "id">;

const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
(
{
Expand All @@ -116,6 +114,7 @@ const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
testId,
translate,
value,
variant = "outline",
},
ref,
) => {
Expand Down Expand Up @@ -144,7 +143,7 @@ const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
});

const renderFieldComponent = useCallback(
({ ariaDescribedBy, id }: FieldRenderProps) => (
({ ariaDescribedBy, id }) => (
<InputBase
{...inputValues}
inputProps={{
Expand All @@ -170,6 +169,8 @@ const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
)
}
id={id}
data-ods-type="search"
data-ods-variant={variant}
name={nameOverride ?? id}
onBlur={onBlur}
onChange={onChange}
Expand Down Expand Up @@ -201,6 +202,7 @@ const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
tabIndex,
testId,
translate,
variant,
],
);

Expand Down
Loading
Loading