Skip to content

feat(field): horizontal field layout improvements - #10865

Open
isBatak wants to merge 11 commits into
chakra-ui:mainfrom
isBatak:feat/horizontal-field-group
Open

feat(field): horizontal field layout improvements#10865
isBatak wants to merge 11 commits into
chakra-ui:mainfrom
isBatak:feat/horizontal-field-group

Conversation

@isBatak

@isBatak isBatak commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

📝 Description

Implement horizontal field layout with proper label-to-input alignment using CSS Grid.

Storybook:
image

Docs:
image

⛳️ Current behavior (updates)

Horizontal field layouts had helper and error text appearing on the same line as the label and input, making it difficult to manage multiple rows of information.

🚀 New behavior

  • Horizontal layout now uses CSS Grid with two columns: fixed label width + flexible input area
  • New part <Field.InputElement> is added, it's optional and used just for styling purposes
  • Label centers vertically to the input element
  • Input/select/textarea/switch elements align to the end of their column
  • Helper text and error text stack below the input in the second column

💣 Is this a breaking change (Yes/No):

No

📝 Additional Information

What changed:

  • Tried the <Field.Group> approach that we discussed internally, but it didn't work because there was no simple way to align the label with the input.
  • Ditched the group approach and implemented the InputElement slot that wraps the input and sets the root to a grid layout. This solved all alignment issues.
  • Label uses alignSelf: center to vertically center to input height, input elements use justifySelf: end for right alignment (useful for switches), and helper/error text flows naturally in the second column based on HTML order.

@changeset-bot

changeset-bot Bot commented Jun 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dabe8ae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@chakra-ui/panda-preset Minor
@chakra-ui/react Minor
@chakra-ui/charts Minor
@chakra-ui/cli Minor
@chakra-ui/codemod Minor
tanstack-router-ts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jun 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chakra-ui-storybook Ready Ready Preview Aug 9, 2026 5:08pm
chakra-v3-docs Ready Ready Preview Aug 9, 2026 5:08pm

Request Review

@Adebesin-Cell Adebesin-Cell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey Ivica, here's what I meant.

Comment on lines +64 to +70
export interface FieldInputElementProps
extends HTMLChakraProps<"input">, UnstyledProp {}

export const FieldInputElement = withContext<
HTMLDivElement,
FieldInputElementProps
>("input", "inputElement")

@Adebesin-Cell Adebesin-Cell Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is the type mismatch I mentioned, the ref is typed HTMLDivElement, but the props and base tag are "input", so they don't line up. And in practice this is always an asChild grid wrapper (it wraps Switch.Root too, which is a div), so it isn't really an input. A neutral div keeps the ref/tag/props consistent and matches how it's used:

Suggested change
export interface FieldInputElementProps
extends HTMLChakraProps<"input">, UnstyledProp {}
export const FieldInputElement = withContext<
HTMLDivElement,
FieldInputElementProps
>("input", "inputElement")
export interface FieldInputElementProps
extends HTMLChakraProps<"div">, UnstyledProp {}
export const FieldInputElement = withContext<
HTMLDivElement,
FieldInputElementProps
>("div", "inputElement")

Comment on lines +51 to +53
group: {
flexDirection: "row",
},

@Adebesin-Cell Adebesin-Cell Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The group here doesn't have a matching slot in the field anatomy, so this block never renders.

Suggested change
group: {
flexDirection: "row",
},

containerType?: ConditionalValue<CssProperties["containerType"] | undefined | AnyString> | undefined
content?: ConditionalValue<CssProperties["content"] | undefined | AnyString> | undefined
contentVisibility?: ConditionalValue<CssProperties["contentVisibility"] | undefined | AnyString> | undefined
// cornerShape?: ConditionalValue<CssProperties["cornerShape"] | undefined | AnyString> | undefined

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we also remove this?

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.

I explained this problem here https://chakraui.slack.com/archives/C049UEYUK7S/p1782042834416699?thread_ts=1781767849.968099&cid=C049UEYUK7S

If I remove this completely, it will appear again on the next code gen. If I uncomment it, we will have TS issue.
I think we need to contribute to the csstype and add cornerShape type definition.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How did I miss that? 🤦

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.

I've figured it out and added local CornerShape augmentation for now
dabe8ae

Maybe we should consider migrating to https://github.com/dev-five-git/csstype-extra or do the same auto-gen ourselves

Automatically generated, up-to-date TypeScript definitions for CSS based on Mozilla's MDN data. Inspired by csstype

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants