-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-field): add useFieldBase_unstable hook #35827
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e0fc677
feat(react-field): add useFieldBase_unstable hook
dmytrokirpa 6a809a3
change file
dmytrokirpa e957873
chore: fix lint errors in react-field base hooks
dmytrokirpa f97e40e
chore: fix formatting and lint in react-field
dmytrokirpa 9a906b4
move icons/styled label component from base hook and add some tests
dmytrokirpa a0026d4
Merge branch 'master' into feat/react-field-base-hooks
dmytrokirpa 6c977e3
Merge branch 'master' into feat/react-field-base-hooks
dmytrokirpa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-field-1731d3b5-2249-4453-8366-3556b93f5000.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "feat: add base hooks for Field", | ||
| "packageName": "@fluentui/react-field", | ||
| "email": "dmytrokirpa@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
packages/react-components/react-field/library/src/components/Field/useField.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import * as React from 'react'; | ||
| import { renderHook } from '@testing-library/react-hooks'; | ||
| import { useField_unstable, useFieldBase_unstable } from './useField'; | ||
|
|
||
| describe('useField_unstable', () => { | ||
| const ref = React.createRef<HTMLDivElement>(); | ||
|
|
||
| it('should return default state when no props are provided', () => { | ||
| const { result } = renderHook(() => useField_unstable({}, ref)); | ||
|
|
||
| expect(result.current).toMatchObject({ | ||
| children: undefined, | ||
| orientation: 'vertical', | ||
| components: { | ||
| label: expect.objectContaining({}), | ||
| }, | ||
| size: 'medium', | ||
| label: undefined, | ||
| validationMessageIcon: undefined, | ||
| validationState: 'none', | ||
| }); | ||
| }); | ||
|
|
||
| it('should return state when props are provided', () => { | ||
| const { result } = renderHook(() => | ||
| useField_unstable( | ||
| { | ||
| orientation: 'horizontal', | ||
| size: 'small', | ||
| label: 'Test Label', | ||
| validationState: 'error', | ||
| }, | ||
| ref, | ||
| ), | ||
| ); | ||
|
|
||
| expect(result.current).toMatchObject({ | ||
| orientation: 'horizontal', | ||
| size: 'small', | ||
| label: expect.objectContaining({ children: 'Test Label' }), | ||
| validationMessageIcon: expect.objectContaining({ children: expect.objectContaining({}) }), | ||
| validationState: 'error', | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('useFieldBase_unstable', () => { | ||
| const ref = React.createRef<HTMLDivElement>(); | ||
|
|
||
| it('should return default state when no props are provided', () => { | ||
| const { result } = renderHook(() => useFieldBase_unstable({}, ref)); | ||
|
|
||
| expect(result.current).toMatchObject({ | ||
| children: undefined, | ||
| components: { | ||
| // Plain HTML element is expected here, as base hook shouldn't know about the "styled" components | ||
| label: 'label', | ||
| }, | ||
| validationMessage: undefined, | ||
| validationMessageIcon: undefined, | ||
| validationState: 'none', | ||
| }); | ||
| }); | ||
|
|
||
| it('should return default state when props are provided', () => { | ||
| const { result } = renderHook(() => | ||
| useFieldBase_unstable( | ||
| { | ||
| label: 'Test Label', | ||
| validationMessage: 'Test Validation Message', | ||
| validationMessageIcon: 'Test Icon', | ||
| validationState: 'error', | ||
| }, | ||
| ref, | ||
| ), | ||
| ); | ||
|
|
||
| expect(result.current).toMatchObject({ | ||
| children: undefined, | ||
| components: { | ||
| // Plain HTML element is expected here, as base hook shouldn't know about the "styled" components | ||
| label: 'label', | ||
| }, | ||
| validationMessage: expect.objectContaining({ children: 'Test Validation Message' }), | ||
| validationMessageIcon: expect.objectContaining({ children: 'Test Icon' }), | ||
| validationState: 'error', | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.