[英]How can I make this dropdown show all of the fifty states instead of “option #”
Right now this code shows a dropdown form that lists "option #".现在,这段代码显示了一个列出“选项#”的下拉表单。 How can I make all of the fifty states selectable instead of the option and a number?
如何使所有 50 个州都可选择而不是选项和数字?
import React, { useState } from 'react';
import {
Box,
FormField,
Grommet,
Select,
MaskedInput,
TextInput
} from 'grommet';
import { grommet } from 'grommet/themes';
const allOptions = Array(50)
.fill()
.map((_, i) => `option ${i + 1}`);
export const Simple = () => {
const [value, setValue] = useState('');
return (
<Grommet theme={grommet}>
<Box align="center" background="light-2" >
<FormField label="State" htmlFor="select" >
<Select
id="select"
placeholder="placeholder"
options={allOptions}
value={value}
onChange={({ option }) => setValue(option)}
/>
</FormField>
</Box>
</Grommet>
);
};
export default {
title: 'Input/FormField/Simple',
};
Please be mindful to use Form+FormField wrappers if required by your app.如果您的应用需要,请注意使用 Form+FormField 包装器。 If the Form context isn't required please remove the FormField wrapper.
如果不需要 Form 上下文,请删除 FormField 包装器。
import React, { useState } from "react";
import { render } from "react-dom";
import { Box, FormField, Grommet, Select } from "grommet";
import { grommet } from "grommet/themes";
// https://gist.github.com/tleen/6299431
const allOptions = [
"Alabama",
"Alaska",
"American Samoa",
"Arizona",
"Arkansas",
"California",
"Colorado",
"Connecticut",
"Delaware",
"District of Columbia",
"Federated States of Micronesia",
"Florida",
"Georgia",
"Guam",
"Hawaii",
"Idaho",
"Illinois",
"Indiana",
"Iowa",
"Kansas",
"Kentucky",
"Louisiana",
"Maine",
"Marshall Islands",
"Maryland",
"Massachusetts",
"Michigan",
"Minnesota",
"Mississippi",
"Missouri",
"Montana",
"Nebraska",
"Nevada",
"New Hampshire",
"New Jersey",
"New Mexico",
"New York",
"North Carolina",
"North Dakota",
"Northern Mariana Islands",
"Ohio",
"Oklahoma",
"Oregon",
"Palau",
"Pennsylvania",
"Puerto Rico",
"Rhode Island",
"South Carolina",
"South Dakota",
"Tennessee",
"Texas",
"Utah",
"Vermont",
"Virgin Island",
"Virginia",
"Washington",
"West Virginia",
"Wisconsin",
"Wyoming"
];
export const App = () => {
const [value, setValue] = useState("");
return (
<Grommet theme={grommet}>
<Box align="center" background="light-2">
<FormField label="State" htmlFor="select">
<Select
id="select"
placeholder="placeholder"
options={allOptions}
value={value}
onChange={({ option }) => setValue(option)}
/>
</FormField>
</Box>
</Grommet>
);
};
render(<App />, document.getElementById("root"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.