Skip to content

feat: Remove horizontal value on FormField and FormFieldGroup orientation prop #3254

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 28 additions & 1 deletion modules/docs/mdx/13.0-UPGRADE-GUIDE.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ any questions.
- [Avatar](#avatar)
- [Expandable](#expandable)
- [External Hyperlink](#external-hyperlink)
- [Form Field and Form Field Group](#form-field-and-form-field-group)
- [Pill](#pill)
- [Tabs](#tabs)
- [Brand Refresh](#brand-refresh)
Expand Down Expand Up @@ -171,9 +172,35 @@ import {Expandable} from '@workday/canvas-kit-react/expandable';
</ExternalHyperlink>
```

### Form Field and Form Field Group
**PR:** [#3101](https://github.com/Workday/canvas-kit/pull/3101)

The `orientation` prop on `FormField` component has been updated to remove the deprecated `horizontal` value. v12 had a codemod to update this value to `horizontalStart`. In v13, we've dropped `horizontal` as a value.` You must update your code to use `horizontalStart`.

**Before in v12**
```tsx
<FormField orientation="horizontal">
<FormField.Label>Label</FormField.Label>
<FormField.Field>
<FormField.Input as={TextInput} />
<FormField.Field>
</FormField>
```

**After in v13**
```tsx
<FormField orientation="horizontalStart">
<FormField.Label>Label</FormField.Label>
<FormField.Field>
<FormField.Input as={TextInput} />
<FormField.Field>
</FormField>
```


### Pill

**PRs:** [#3104](https://github.com/Workday/canvas-kit/pull/3104)
**PR:** [#3104](https://github.com/Workday/canvas-kit/pull/3104)

A few changes have been made to `Pill` to ensure proper accessibility and styles.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const Basic = () => {
return (
<>
<MultiSelect items={items} initialSelectedIds={['Olives', 'Onions', 'Pepperoni']}>
<FormField orientation="horizontal">
<FormField orientation="horizontalStart">
<FormField.Label>Toppings</FormField.Label>
<FormField.Input
as={MultiSelect.Input}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const Complex = () => {
>
<main className={mainContentStyles}>
<MultiSelect items={items} getId={i => i.id} getTextValue={i => i.text}>
<FormField orientation="horizontal">
<FormField orientation="horizontalStart">
<FormField.Label>Toppings</FormField.Label>
<FormField.Input
as={MultiSelect.Input}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const Controlled = () => {
>
<Flex gap="s" flexDirection="column">
<MultiSelect items={items}>
<FormField orientation="horizontal">
<FormField orientation="horizontalStart">
<FormField.Label>Toppings</FormField.Label>
<FormField.Input
as={MultiSelect.Input}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const items = [
export const Icons = () => {
return (
<MultiSelect items={items}>
<FormField orientation="horizontal">
<FormField orientation="horizontalStart">
<FormField.Label>Controls</FormField.Label>
<FormField.Input
as={MultiSelect.Input}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const Searching = () => {
>
<main className={mainContentStyles}>
<MultiSelect model={model}>
<FormField orientation="horizontal">
<FormField orientation="horizontalStart">
<FormField.Label>Fruits</FormField.Label>
<FormField.Input
as={MultiSelect.SearchInput}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {controlComponent} from '../../../../../../utils/storybook';

export const DefaultWithCustomOptionsLeft = () => {
return (
<FormField orientation="horizontal" id="select-default-custom">
<FormField orientation="horizontalStart" id="select-default-custom">
<FormField.Label>Label</FormField.Label>
<FormField.Field>
{controlComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {controlComponent} from '../../../../../../utils/storybook';

export const DefaultWithSimpleOptionsLeft = () => {
return (
<FormField orientation="horizontal" id="select-default-simple">
<FormField orientation="horizontalStart" id="select-default-simple">
<FormField.Label>Label</FormField.Label>
<FormField.Field>
{controlComponent(<FormField.Input as={Select} name="state" options={simpleOptions} />)}
Expand Down
2 changes: 1 addition & 1 deletion modules/preview-react/text-area/lib/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const TextArea = createContainer('div')({
elemProps,
formFieldStencil({
grow,
orientation: orientation === 'horizontal' ? 'horizontalStart' : orientation,
orientation: orientation,
error: model.state.error,
required: model.state.isRequired,
})
Expand Down
2 changes: 1 addition & 1 deletion modules/preview-react/text-input/lib/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const TextInput = createContainer('div')({
elemProps,
formFieldStencil({
grow,
orientation: orientation === 'horizontal' ? 'horizontalStart' : orientation,
orientation: orientation,
error: model.state.error,
required: model.state.isRequired,
})
Expand Down
19 changes: 4 additions & 15 deletions modules/react/form-field/lib/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import {FormFieldContainer} from './FormFieldContainer';
import {formFieldStencil} from './formFieldStencil';
import {FormFieldField} from './FormFieldField';

//TODO: Remove `horizontal` option in v13 and the console warn message.
export interface FormFieldProps extends FlexProps, GrowthBehavior {
/**
* The direction the child elements should stack. In v13, `horizontal` will be removed. Please use `horizontalStart` or `horizontalEnd` for horizontal alignment.
* @default vertical
*/
orientation?: 'vertical' | 'horizontalStart' | 'horizontalEnd' | 'horizontal';
orientation?: 'vertical' | 'horizontalStart' | 'horizontalEnd';
children: React.ReactNode;
}

Expand Down Expand Up @@ -100,7 +99,7 @@ export const FormField = createContainer('div')({
/**
* `FormField.Field` allows you to customize container alignment and styles when wrapping your input and hint text.
* ```tsx
* <FormField orientation="horizontal">
* <FormField orientation="horizontalStart">
* <FormField.Label>First Name</FormField.Label>
* <FormField.Field>
* <FormField.Input as={TextInput} value={value} onChange={(e) => console.log(e)} />
Expand All @@ -111,24 +110,14 @@ export const FormField = createContainer('div')({
*/
Field: FormFieldField,
},
})<FormFieldProps>(({children, grow, orientation, ...elemProps}, Element, model) => {
// TODO: Remove this warning in v13 once we remove horizontal support in favor of horizontalStart and horizontalEnd.
if (process.env.NODE_ENV === 'development') {
if (orientation === 'horizontal') {
console.warn(
'FormField: Orientation option of "horizontal" is deprecated and will be removed in v13. Please update your types and value to use the string literal of "horizontalStart". The following values will be accepted in v13: "horizontalStart" | "horizontalEnd" | "vertical".'
);
}
}

})<FormFieldProps>(({children, grow, orientation = 'vertical', ...elemProps}, Element, model) => {
return (
<Element
{...mergeStyles(
elemProps,
formFieldStencil({
grow,
orientation:
model.state.orientation === 'horizontal' ? 'horizontalStart' : model.state.orientation,
orientation: model.state.orientation,
error: model.state.error,
required: model.state.isRequired,
})
Expand Down
5 changes: 2 additions & 3 deletions modules/react/form-field/lib/FormFieldGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface FormFieldGroupProps extends FlexProps, GrowthBehavior {
* The direction the child elements should stack. In v13, `horizontal` will be removed. Please use `horizontalStart` or `horizontalEnd` for horizontal alignment.
* @default vertical
*/
orientation?: 'vertical' | 'horizontalStart' | 'horizontalEnd' | 'horizontal';
orientation?: 'vertical' | 'horizontalStart' | 'horizontalEnd';
children: React.ReactNode;
}

Expand Down Expand Up @@ -120,8 +120,7 @@ export const FormFieldGroup = createContainer('div')({
elemProps,
formFieldStencil({
grow,
orientation:
model.state.orientation === 'horizontal' ? 'horizontalStart' : model.state.orientation,
orientation: model.state.orientation,
error: model.state.error,
required: model.state.isRequired,
})
Expand Down
3 changes: 1 addition & 2 deletions modules/react/form-field/lib/FormFieldGroupLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ export const FormFieldGroupLabel = createSubcomponent('div')({
typeLevel,
variant,
isRequired: model.state.isRequired as any,
orientation:
model.state.orientation === 'horizontal' ? 'horizontalStart' : model.state.orientation,
orientation: model.state.orientation,
})
)}
>
Expand Down
5 changes: 1 addition & 4 deletions modules/react/form-field/lib/FormFieldLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ export const FormFieldLabel = createSubcomponent('label')({
variant,
isHidden: isHidden ? 'true' : undefined,
isRequired: model.state.isRequired as any,
orientation:
model.state.orientation === 'horizontal'
? 'horizontalStart'
: model.state.orientation,
orientation: model.state.orientation,
})
)}
>
Expand Down
2 changes: 1 addition & 1 deletion modules/react/form-field/lib/hooks/useFormFieldModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const useFormFieldModel = createModelHook({
*/
isRequired: false,

orientation: 'vertical' as 'vertical' | 'horizontal' | 'horizontalEnd' | 'horizontalStart',
orientation: 'vertical' as 'vertical' | 'horizontalEnd' | 'horizontalStart',
},
})(config => {
const id = useUniqueId(config.id);
Expand Down
2 changes: 1 addition & 1 deletion modules/react/radio/stories/visualTesting.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const RadioStates = () => (

<h3>RadioGroup (wrapping)</h3>
<div style={{maxWidth: 480}}>
<FormField orientation="horizontal" as="fieldset">
<FormField orientation="horizontalStart" as="fieldset">
<FormField.Label as="legend">
Really long label. Really long label. Really long label. Really long label. Really long
label. Really long label.
Expand Down
Loading