Files
react-test/docs/data/joy/components/autocomplete/ControllableStates.js
how2ice 005cf56baf
Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
init project
2025-12-12 14:26:25 +09:00

51 lines
1.5 KiB
JavaScript

import * as React from 'react';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Autocomplete from '@mui/joy/Autocomplete';
import Typography from '@mui/joy/Typography';
const options = ['Option 1', 'Option 2'];
export default function ControllableStates() {
const [value, setValue] = React.useState(options[0]);
const [inputValue, setInputValue] = React.useState('');
return (
<div>
<Typography level="body-sm" sx={{ mb: 1 }}>
<code>value: </code>
<Typography variant="soft" sx={{ py: 0.4 }}>
<code>
<strong>{`${value !== null ? `'${value}'` : 'null'}`}</strong>
</code>
</Typography>
</Typography>
<Typography level="body-sm">
<code>inputValue: </code>
<Typography variant="soft" sx={{ py: 0.4 }}>
<code>
<strong>{`'${inputValue}'`}</strong>
</code>
</Typography>
</Typography>
<br />
<FormControl id="controllable-states-demo">
<FormLabel>Controllable</FormLabel>
<Autocomplete
placeholder="Controllable"
value={value}
onChange={(event, newValue) => {
setValue(newValue);
}}
inputValue={inputValue}
onInputChange={(event, newInputValue) => {
setInputValue(newInputValue);
}}
options={options}
sx={{ width: 300 }}
/>
</FormControl>
</div>
);
}