Skip to content

Commit

Permalink
feat: add state style prop support for FormControl (#8102)
Browse files Browse the repository at this point in the history
* feat(form-control): add state data attributes to FormControl

* chore: add changeset

* test: amend data attribute test to also check FormControl
  • Loading branch information
nikparo committed Nov 9, 2023
1 parent b6befea commit 389ff61
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/honest-tigers-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@chakra-ui/form-control": minor
---

Allow theming FormControl through state style props and its children through
\_group\* style props
6 changes: 5 additions & 1 deletion packages/components/form-control/src/form-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,12 @@ function useFormControlProvider(props: FormControlContext) {
...htmlProps,
ref: forwardedRef,
role: "group",
"data-focus": dataAttr(isFocused),
"data-disabled": dataAttr(isDisabled),
"data-invalid": dataAttr(isInvalid),
"data-readonly": dataAttr(isReadOnly),
}),
[htmlProps],
[htmlProps, isDisabled, isFocused, isInvalid, isReadOnly],
)

const getRequiredIndicatorProps = useCallback<PropGetter>(
Expand Down
6 changes: 6 additions & 0 deletions packages/components/form-control/tests/form-control.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ test("has the correct data attributes", async () => {

fireEvent.focus(screen.getByLabelText(/Name/))

const control = screen.getByTestId("control")
expect(control).toHaveAttribute("data-focus")
expect(control).toHaveAttribute("data-disabled")
expect(control).toHaveAttribute("data-invalid")
expect(control).toHaveAttribute("data-readonly")

const label = screen.getByTestId("label")
expect(label).toHaveAttribute("data-focus")
expect(label).toHaveAttribute("data-invalid")
Expand Down

1 comment on commit 389ff61

@vercel
Copy link

@vercel vercel bot commented on 389ff61 Nov 9, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.