mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-19 22:12:10 +01:00
Cleanup Autocomplete component (#1917)
Extract common properties for both autocomplete variations.
This commit is contained in:
@@ -88,48 +88,40 @@ class Autocomplete extends React.Component<Props, State> {
|
||||
disabled
|
||||
} = this.props;
|
||||
|
||||
const asyncProps = {
|
||||
className: "autocomplete-entry",
|
||||
classNamePrefix: "autocomplete-entry",
|
||||
cacheOptions: true,
|
||||
loadOptions: loadSuggestions,
|
||||
onChange: this.handleInputChange,
|
||||
value,
|
||||
placeholder,
|
||||
loadingMessage: () => loadingMessage,
|
||||
noOptionsMessage: () => noOptionsMessage,
|
||||
isDisabled: disabled,
|
||||
"aria-label": helpText || label
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={classNames("field", className)}>
|
||||
<LabelWithHelpIcon label={label} helpText={helpText} />
|
||||
<div className="control">
|
||||
{creatable ? (
|
||||
<AsyncCreatable
|
||||
className="autocomplete-entry"
|
||||
classNamePrefix="autocomplete-entry"
|
||||
cacheOptions
|
||||
loadOptions={loadSuggestions}
|
||||
onChange={this.handleInputChange}
|
||||
value={value}
|
||||
placeholder={placeholder}
|
||||
loadingMessage={() => loadingMessage}
|
||||
noOptionsMessage={() => noOptionsMessage}
|
||||
{...asyncProps}
|
||||
isValidNewOption={this.isValidNewOption}
|
||||
onCreateOption={value => {
|
||||
onCreateOption={newValue => {
|
||||
this.selectValue({
|
||||
label: value,
|
||||
label: newValue,
|
||||
value: {
|
||||
id: value,
|
||||
displayName: value
|
||||
id: newValue,
|
||||
displayName: newValue
|
||||
}
|
||||
});
|
||||
}}
|
||||
aria-label={helpText || label}
|
||||
isDisabled={disabled}
|
||||
/>
|
||||
) : (
|
||||
<Async
|
||||
className="autocomplete-entry"
|
||||
classNamePrefix="autocomplete-entry"
|
||||
cacheOptions
|
||||
loadOptions={loadSuggestions}
|
||||
onChange={this.handleInputChange}
|
||||
value={value}
|
||||
placeholder={placeholder}
|
||||
loadingMessage={() => loadingMessage}
|
||||
noOptionsMessage={() => noOptionsMessage}
|
||||
aria-label={helpText || label}
|
||||
isDisabled={disabled}
|
||||
/>
|
||||
<Async {...asyncProps} />
|
||||
)}
|
||||
</div>
|
||||
{errorMessage ? <p className="help is-danger">{errorMessage}</p> : null}
|
||||
|
||||
Reference in New Issue
Block a user