Skip to content

feat(react-field): add useFieldBase_unstable hook#35827

Merged
dmytrokirpa merged 7 commits into
masterfrom
feat/react-field-base-hooks
Mar 31, 2026
Merged

feat(react-field): add useFieldBase_unstable hook#35827
dmytrokirpa merged 7 commits into
masterfrom
feat/react-field-base-hooks

Conversation

@dmytrokirpa

@dmytrokirpa dmytrokirpa commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds a base state hook for the Field component as part of the experimental base hooks initiative.

What was implemented

  • useFieldBase_unstable — base hook for Field component
    • Props type: FieldBaseProps (omits orientation, size)
    • State type: FieldBaseState (omits orientation, size)
    • Handles:
      • validationState defaulting ('error' when validationMessage is set, 'none' otherwise)
      • role="alert" on validationMessage for error and warning states
      • ID generation (useId) for form control association (generatedControlId)
      • Label slot with htmlFor, id, required props
      • ValidationMessage slot with id and role
      • Hint slot with id
      • ValidationMessageIcon slot with appropriate icon (ErrorCircle12Filled, Warning12Filled, CheckmarkCircle12Filled, or none)
      • Slot structure (root, label, validationMessage, validationMessageIcon, hint)

Note on size

The size prop controls the label's size. In useField_unstable, after calling useFieldBase_unstable, the size value is merged into the label slot's props. orientation is added directly to the returned state object.

Exports

All new types and hooks are exported from the package index.ts. They are NOT exported from @fluentui/react-components.

Test plan

  • TypeScript compilation passes (npx tsc --noEmit on the package)
  • Existing Field rendering unchanged
  • Validation states (error, warning, success) still render correct icons and ARIA attributes
  • Label correctly associates with the control via htmlFor
  • New base hook can be used independently without design props

🤖 Generated with Claude Code

@dmytrokirpa dmytrokirpa changed the base branch from experimental/component-base-hooks to master March 5, 2026 09:54
dmytrokirpa and others added 2 commits March 5, 2026 12:12
Implements base state hook for Field component as part of the experimental base hooks initiative.
The base hook extracts pure component logic while omitting design props (orientation, size).

- FieldBaseProps: omits orientation, size
- FieldBaseState: omits orientation, size
- useFieldBase_unstable: handles
  - validationState with role="alert" for error/warning messages
  - ID generation (baseId, generatedControlId) for form control association
  - label slot with htmlFor, id, required
  - validationMessage slot with id, role
  - hint slot with id
  - validationMessageIcon slot with appropriate icon based on validationState
  - slot structure (root, label, validationMessage, validationMessageIcon, hint)

useField_unstable now calls useFieldBase_unstable and adds orientation, size design props.
The size prop is merged into the label slot's props.
All new types and hooks exported from package index.ts.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@dmytrokirpa dmytrokirpa force-pushed the feat/react-field-base-hooks branch from 013b527 to 6a809a3 Compare March 5, 2026 11:13
@github-actions

github-actions Bot commented Mar 5, 2026

Copy link
Copy Markdown

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-components
react-components: entire library
1.297 MB
324.139 kB
1.297 MB
324.234 kB
260 B
95 B
react-field
Field
22.133 kB
8.35 kB
22.393 kB
8.383 kB
260 B
33 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-checkbox
Checkbox
33.458 kB
11.375 kB
react-combobox
Combobox (including child components)
105.208 kB
34.168 kB
react-combobox
Dropdown (including child components)
105.832 kB
34.1 kB
react-components
react-components: Button, FluentProvider & webLightTheme
70.397 kB
19.96 kB
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
236.743 kB
68.75 kB
react-components
react-components: FluentProvider & webLightTheme
43.612 kB
14.022 kB
react-datepicker-compat
DatePicker Compat
225.158 kB
63.633 kB
react-input
Input
26.28 kB
8.702 kB
react-list
List
87.11 kB
25.762 kB
react-list
ListItem
110.775 kB
32.629 kB
react-portal-compat
PortalCompatProvider
8.386 kB
2.624 kB
react-progress
ProgressBar
20.097 kB
7.834 kB
react-radio
Radio
31.087 kB
9.656 kB
react-radio
RadioGroup
14.035 kB
5.7 kB
react-select
Select
26.085 kB
9.437 kB
react-slider
Slider
36.356 kB
12.08 kB
react-spinbutton
SpinButton
33.804 kB
11.125 kB
react-swatch-picker
@fluentui/react-swatch-picker - package
104.305 kB
29.944 kB
react-switch
Switch
36.155 kB
11.016 kB
react-table
DataGrid
159.531 kB
44.975 kB
react-table
Table (Primitives only)
40.997 kB
13.172 kB
react-table
Table as DataGrid
130.752 kB
35.992 kB
react-table
Table (Selection only)
69.139 kB
19.357 kB
react-table
Table (Sort only)
67.782 kB
18.973 kB
react-tag-picker
@fluentui/react-tag-picker - package
186.596 kB
55.849 kB
react-textarea
Textarea
24.668 kB
8.969 kB
react-timepicker-compat
TimePicker
108.174 kB
35.695 kB
react-tree
FlatTree
147.853 kB
42.169 kB
react-tree
PersonaFlatTree
149.681 kB
42.544 kB
react-tree
PersonaTree
145.741 kB
41.373 kB
react-tree
Tree
143.919 kB
41.004 kB
🤖 This report was generated against e89fd73d5695771e599d74828e4fc1fd7c375f55

@github-actions

github-actions Bot commented Mar 5, 2026

Copy link
Copy Markdown

Pull request demo site: URL

@dmytrokirpa dmytrokirpa marked this pull request as ready for review March 31, 2026 09:58
@dmytrokirpa dmytrokirpa requested a review from a team as a code owner March 31, 2026 09:58
@dmytrokirpa dmytrokirpa enabled auto-merge (squash) March 31, 2026 20:40
@dmytrokirpa dmytrokirpa merged commit 3814685 into master Mar 31, 2026
15 checks passed
tudorpopams pushed a commit to tudorpopams/fluentui that referenced this pull request Apr 14, 2026
@dmytrokirpa dmytrokirpa deleted the feat/react-field-base-hooks branch May 23, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants