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

Add isFullWidth option to form fields #2056

Merged
merged 2 commits into from
Dec 1, 2023
Merged
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
4 changes: 3 additions & 1 deletion packages/odyssey-react-mui/src/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export type AutocompleteProps<
getIsOptionEqualToValue?: (option: OptionType, value: OptionType) => boolean;
} & Pick<
FieldComponentProps,
"errorMessage" | "hint" | "id" | "isOptional" | "name"
"errorMessage" | "hint" | "id" | "isOptional" | "name" | "isFullWidth"
> &
SeleniumProps;

Expand All @@ -177,6 +177,7 @@ const Autocomplete = <
inputValue,
isCustomValueAllowed,
isDisabled,
isFullWidth = false,
isLoading,
isOptional = false,
isReadOnly,
Expand Down Expand Up @@ -309,6 +310,7 @@ const Autocomplete = <
freeSolo={isCustomValueAllowed}
filterSelectedOptions={true}
id={idOverride}
fullWidth={isFullWidth}
loading={isLoading}
multiple={hasMultipleChoices}
onBlur={onBlur}
Expand Down
6 changes: 6 additions & 0 deletions packages/odyssey-react-mui/src/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export type FieldProps = {
* If `true`, the component is disabled.
*/
isDisabled?: boolean;
/**
* If `true`, the component can stretch to fill the width of the container.
jordankoschei-okta marked this conversation as resolved.
Show resolved Hide resolved
*/
isFullWidth?: boolean;
/**
* If `true`, the `input` element is not required.
*/
Expand Down Expand Up @@ -96,6 +100,7 @@ const Field = ({
hint,
id: idOverride,
isDisabled: isDisabledProp = false,
isFullWidth = false,
isRadioGroup = false,
isOptional = false,
label,
Expand Down Expand Up @@ -126,6 +131,7 @@ const Field = ({
disabled={isDisabled}
error={Boolean(errorMessage)}
role={isRadioGroup ? "radiogroup" : undefined}
fullWidth={isFullWidth}
>
{fieldType === "group" ? (
<MuiFormLabel component="legend">
Expand Down
4 changes: 4 additions & 0 deletions packages/odyssey-react-mui/src/FieldComponentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export type FieldComponentProps = {
* If `true`, the component is disabled.
*/
isDisabled?: boolean;
/**
* If `true`, the component can stretch to fill the width of the container.
*/
isFullWidth?: boolean;
/**
* If `true`, the `input` element is not required.
*/
Expand Down
4 changes: 3 additions & 1 deletion packages/odyssey-react-mui/src/NativeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export type NativeSelectProps<
value?: Value;
} & Pick<
FieldComponentProps,
"errorMessage" | "hint" | "id" | "isDisabled" | "isOptional"
"errorMessage" | "hint" | "id" | "isDisabled" | "isOptional" | "isFullWidth"
> &
SeleniumProps;

Expand All @@ -97,6 +97,7 @@ const NativeSelect: ForwardRefWithType = forwardRef(
hint,
id: idOverride,
isDisabled = false,
isFullWidth = false,
isMultiSelect,
isOptional = false,
label,
Expand Down Expand Up @@ -179,6 +180,7 @@ const NativeSelect: ForwardRefWithType = forwardRef(
hint={hint}
id={idOverride}
isDisabled={isDisabled}
isFullWidth={isFullWidth}
isOptional={isOptional}
label={label}
renderFieldComponent={renderFieldComponent}
Expand Down
2 changes: 2 additions & 0 deletions packages/odyssey-react-mui/src/PasswordField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const PasswordField = forwardRef<HTMLInputElement, PasswordFieldProps>(
hint,
id: idOverride,
isDisabled = false,
isFullWidth = false,
isOptional = false,
hasShowPassword = true,
isReadOnly,
Expand Down Expand Up @@ -199,6 +200,7 @@ const PasswordField = forwardRef<HTMLInputElement, PasswordFieldProps>(
hint={hint}
id={idOverride}
isDisabled={isDisabled}
isFullWidth={isFullWidth}
isOptional={isOptional}
label={label}
renderFieldComponent={renderFieldComponent}
Expand Down
4 changes: 3 additions & 1 deletion packages/odyssey-react-mui/src/SearchField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export type SearchFieldProps = {
* The value of the `input` element, to use when controlled.
*/
value?: string;
} & Pick<FieldComponentProps, "id" | "isDisabled" | "name"> &
} & Pick<FieldComponentProps, "id" | "isDisabled" | "name" | "isFullWidth"> &
SeleniumProps;

const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
Expand All @@ -89,6 +89,7 @@ const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
hasInitialFocus,
id: idOverride,
isDisabled = false,
isFullWidth = false,
label,
name: nameOverride,
onChange: onChangeProp,
Expand Down Expand Up @@ -186,6 +187,7 @@ const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
hasVisibleLabel={false}
id={idOverride}
isDisabled={isDisabled}
isFullWidth={isFullWidth}
isOptional={true}
label={label}
renderFieldComponent={renderFieldComponent}
Expand Down
10 changes: 9 additions & 1 deletion packages/odyssey-react-mui/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ export type SelectProps<
value?: Value;
} & Pick<
FieldComponentProps,
"errorMessage" | "hint" | "id" | "isDisabled" | "isOptional" | "name"
| "errorMessage"
| "hint"
| "id"
| "isDisabled"
| "isOptional"
| "name"
| "isFullWidth"
> &
SeleniumProps;

Expand Down Expand Up @@ -114,6 +120,7 @@ const Select = <
hint,
id: idOverride,
isDisabled = false,
isFullWidth = false,
isMultiSelect,
isOptional = false,
label,
Expand Down Expand Up @@ -282,6 +289,7 @@ const Select = <
hint={hint}
id={idOverride}
isDisabled={isDisabled}
isFullWidth={isFullWidth}
isOptional={isOptional}
label={label}
renderFieldComponent={renderFieldComponent}
Expand Down
2 changes: 2 additions & 0 deletions packages/odyssey-react-mui/src/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
hint,
id: idOverride,
isDisabled = false,
isFullWidth = false,
isMultiline = false,
isOptional = false,
isReadOnly,
Expand Down Expand Up @@ -205,6 +206,7 @@ const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
hint={hint}
id={idOverride}
isDisabled={isDisabled}
isFullWidth={isFullWidth}
isOptional={isOptional}
label={label}
renderFieldComponent={renderFieldComponent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const storybookMeta: Meta<typeof Autocomplete> = {
},
},
isDisabled: fieldComponentPropsMetaData.isDisabled,
isFullWidth: fieldComponentPropsMetaData.isFullWidth,
isLoading: {
control: "boolean",
description: "Displays a loading indicator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const storybookMeta: Meta<typeof NativeSelect> = {
hint: fieldComponentPropsMetaData.hint,
id: fieldComponentPropsMetaData.id,
isDisabled: fieldComponentPropsMetaData.isDisabled,
isFullWidth: fieldComponentPropsMetaData.isFullWidth,
isMultiSelect: {
control: "boolean",
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const storybookMeta: Meta<typeof PasswordField> = {
hint: fieldComponentPropsMetaData.hint,
id: fieldComponentPropsMetaData.id,
isDisabled: fieldComponentPropsMetaData.isDisabled,
isFullWidth: fieldComponentPropsMetaData.isFullWidth,
isOptional: fieldComponentPropsMetaData.isOptional,
isReadOnly: fieldComponentPropsMetaData.isReadOnly,
label: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const storybookMeta: Meta<typeof SearchField> = {
},
},
isDisabled: fieldComponentPropsMetaData.isDisabled,
isFullWidth: fieldComponentPropsMetaData.isFullWidth,
id: fieldComponentPropsMetaData.id,
label: {
control: "text",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { MuiThemeDecorator } from "../../../../.storybook/components";
import { userEvent, waitFor, screen } from "@storybook/testing-library";
import { axeRun } from "../../../axe-util";
import { expect } from "@storybook/jest";
import { fieldComponentPropsMetaData } from "../../../fieldComponentPropsMetaData";
import { useCallback, useState } from "react";

const optionsArray: SelectProps<string | string[], boolean>["options"] = [
Expand Down Expand Up @@ -120,15 +121,7 @@ const storybookMeta: Meta<SelectProps<string | string[], boolean>> = {
},
},
},
errorMessage: {
control: "text",
description: "The error message for the select component",
table: {
type: {
summary: "string",
},
},
},
errorMessage: fieldComponentPropsMetaData.errorMessage,
hasMultipleChoices: {
control: "boolean",
description: "If `true`, the select component allows multiple selections",
Expand All @@ -141,36 +134,10 @@ const storybookMeta: Meta<SelectProps<string | string[], boolean>> = {
},
},
},
hint: {
control: "text",
description: "The hint text for the select component",
table: {
type: {
summary: "string",
},
},
},
id: {
control: "text",
description: "The id attribute of the select component",
table: {
type: {
summary: "string",
},
},
},
isDisabled: {
control: "boolean",
description: "If `true`, the select component is disabled",
table: {
type: {
summary: "boolean",
},
defaultValue: {
summary: false,
},
},
},
hint: fieldComponentPropsMetaData.hint,
id: fieldComponentPropsMetaData.id,
isDisabled: fieldComponentPropsMetaData.isFullWidth,
isFullWidth: fieldComponentPropsMetaData.isFullWidth,
isOptional: {
control: "boolean",
description: "If `true`, the select component is optional",
Expand All @@ -196,16 +163,7 @@ const storybookMeta: Meta<SelectProps<string | string[], boolean>> = {
name: "string",
},
},
name: {
control: "text",
description:
"The name of the select component. Defaults to the `id` if not set.",
table: {
type: {
summary: "string",
},
},
},
name: fieldComponentPropsMetaData.name,
onBlur: {
control: null,
description: "Callback fired when the select component loses focus",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const storybookMeta: Meta<typeof TextField> = {
hint: fieldComponentPropsMetaData.hint,
id: fieldComponentPropsMetaData.id,
isDisabled: fieldComponentPropsMetaData.isDisabled,
isFullWidth: fieldComponentPropsMetaData.isFullWidth,
isMultiline: {
control: "boolean",
description: "If `true`, a TextareaAutosize element is rendered",
Expand Down
13 changes: 13 additions & 0 deletions packages/odyssey-storybook/src/fieldComponentPropsMetaData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ export const fieldComponentPropsMetaData: Partial<
},
},
},
isFullWidth: {
control: "boolean",
description:
"If `true`, the component can stretch to fill the width of the container",
table: {
type: {
summary: "boolean",
},
defaultValue: {
summary: false,
},
},
},
isOptional: {
control: "boolean",
description: "If `true`, the `input` element is not required",
Expand Down