diff --git a/pages/en-us/components/auto-complete.mdx b/pages/en-us/components/auto-complete.mdx index 89e3d91..38f6c63 100644 --- a/pages/en-us/components/auto-complete.mdx +++ b/pages/en-us/components/auto-complete.mdx @@ -40,10 +40,25 @@ AutoComplete control of input field. } `} /> + { + const options = [ + { label: 'London', value: 'london' }, + { label: 'Sydney', value: 'sydney' }, + { label: 'Shanghai', value: 'shanghai' }, + ] + return +} +`} /> + { const allOptions = [ @@ -51,7 +66,7 @@ AutoComplete control of input field. { label: 'Sydney', value: 'sydney' }, { label: 'Shanghai', value: 'shanghai' }, ] - const [options, setOptions] = useState() + const [options, setOptions] = React.useState() const searchHandler = (currentValue) => { if (!currentValue) return setOptions([]) const relatedOptions = allOptions.filter(item => item.value.includes(currentValue)) @@ -216,6 +231,31 @@ AutoComplete control of input field. } `} /> + { + const allOptions = [ + { label: 'London', value: 'london' }, + { label: 'Sydney', value: 'sydney' }, + { label: 'Shanghai', value: 'shanghai' }, + ] + const [options, setOptions] = React.useState() + const searchHandler = (currentValue) => { + const createOptions = [{ + value: currentValue, label: 'Add "' + currentValue + '"' + }] + if (!currentValue) return setOptions([]) + const relatedOptions = allOptions.filter(item => item.value.includes(currentValue)) + const optionsWithCreatable = relatedOptions.length !== 0 ? relatedOptions : createOptions + setOptions(optionsWithCreatable) + } + return +} +`} /> + AutoComplete.Props @@ -235,6 +275,7 @@ AutoComplete control of input field. | **dropdownClassName** | className of dropdown box | `string` | - | - | | **dropdownStyle** | style of dropdown box | `object` | - | - | | **disableMatchWidth** | disable Option from follow parent width | `boolean` | - | `false` | +| **disableFreeSolo** | only values can be changed through Select | `boolean` | - | `false` | | ... | native props | `InputHTMLAttributes` | `'id', 'className', ...` | - | AutoComplete.Item diff --git a/pages/zh-cn/components/auto-complete.mdx b/pages/zh-cn/components/auto-complete.mdx index d83ab30..f3fc33e 100644 --- a/pages/zh-cn/components/auto-complete.mdx +++ b/pages/zh-cn/components/auto-complete.mdx @@ -26,6 +26,21 @@ export const meta = { } `} /> + { + const options = [ + { label: 'London', value: 'london' }, + { label: 'Sydney', value: 'sydney' }, + { label: 'Shanghai', value: 'shanghai' }, + ] + return +} +`} /> + + + { + const allOptions = [ + { label: 'London', value: 'london' }, + { label: 'Sydney', value: 'sydney' }, + { label: 'Shanghai', value: 'shanghai' }, + ] + const [options, setOptions] = React.useState() + const searchHandler = (currentValue) => { + const createOptions = [{ + value: currentValue, label: 'Add "' + currentValue + '"' + }] + if (!currentValue) return setOptions([]) + const relatedOptions = allOptions.filter(item => item.value.includes(currentValue)) + const optionsWithCreatable = relatedOptions.length !== 0 ? relatedOptions : createOptions + setOptions(optionsWithCreatable) + } + return +} +`} /> + AutoComplete.Props @@ -236,6 +277,7 @@ export const meta = { | **dropdownClassName** | 自定义下拉框的类名 | `string` | - | - | | **dropdownStyle** | 自定义下拉框的样式 | `object` | - | - | | **disableMatchWidth** | 禁止 Option 跟随父元素的宽度 | `boolean` | - | `false` | +| **disableFreeSolo** | 只允许通过 Select 事件更改值 (禁止 Input 输入随意值) | `boolean` | - | `false` | | ... | 原生属性 | `InputHTMLAttributes` | `'id', 'className', ...` | - | AutoComplete.Item