-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Add a default unique id for useInput
#9788
Merged
Merged
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c9c7594
Add logic + doc
erwanMarmelab 97ef286
WIP : how to test
erwanMarmelab 8268099
fix cypress test
erwanMarmelab f11125c
fix spec tests
erwanMarmelab ddc2ff4
adapt tests
erwanMarmelab 03ad677
work with useId
erwanMarmelab 0fc59a0
remove the 1st loading
erwanMarmelab 9cf621e
fix cypress tests
erwanMarmelab b74553e
just defaultId
erwanMarmelab b125d7c
change doc default definition
erwanMarmelab d74a42a
change input id
erwanMarmelab eca2b4d
fix RichTextInput tests
erwanMarmelab 85092d1
add an upgrade guide section
erwanMarmelab 5418967
Merge branch 'next' into feat/add-default-unique-id-for-useInput
erwanMarmelab 5cfa4b8
explain for tests
erwanMarmelab df41f11
Merge branch 'next' into feat/add-default-unique-id-for-useInput
djhi 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
This file contains 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 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 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 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,43 @@ | ||
import * as React from 'react'; | ||
import { CoreAdminContext } from '../core'; | ||
import { Form } from './Form'; | ||
import { useInput } from './useInput'; | ||
|
||
export default { | ||
title: 'ra-core/form/useInput', | ||
}; | ||
|
||
const Input = ({ source }) => { | ||
const { id, field, fieldState } = useInput({ source }); | ||
|
||
return ( | ||
<label htmlFor={id}> | ||
{id}: <input id={id} {...field} /> | ||
{fieldState.error && <span>{fieldState.error.message}</span>} | ||
</label> | ||
); | ||
}; | ||
|
||
export const Basic = () => { | ||
const [submittedData, setSubmittedData] = React.useState<any>(); | ||
return ( | ||
<CoreAdminContext> | ||
<Form onSubmit={data => setSubmittedData(data)}> | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: '1em', | ||
marginBottom: '1em', | ||
}} | ||
> | ||
<Input source="field1" /> | ||
<Input source="field2" /> | ||
<Input source="field3" /> | ||
</div> | ||
<button type="submit">Submit</button> | ||
</Form> | ||
<pre>{JSON.stringify(submittedData, null, 2)}</pre> | ||
</CoreAdminContext> | ||
); | ||
}; |
This file contains 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should leverage
useId
ifid
is not providedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applied