Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9788 from marmelab/feat/add-default-unique-id-for…
…-useInput Add a default unique id for `useInput`
- Loading branch information
Showing
9 changed files
with
103 additions
and
18 deletions.
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
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