mirror of
				https://github.com/scm-manager/scm-manager.git
				synced 2025-11-03 20:15:52 +01:00 
			
		
		
		
	Add preselected value to options in DropDown.tsx if missing
This commit is contained in:
		@@ -48,4 +48,14 @@ storiesOf("Forms|DropDown", module)
 | 
			
		||||
        // nothing to do
 | 
			
		||||
      }}
 | 
			
		||||
    />
 | 
			
		||||
  ))
 | 
			
		||||
  .add("Add preselect if missing in options", () => (
 | 
			
		||||
    <DropDown
 | 
			
		||||
      optionValues={["alpha", "beta", "gamma"]}
 | 
			
		||||
      options={["A", "B", "C"]}
 | 
			
		||||
      preselectedOption={"D"}
 | 
			
		||||
      optionSelected={selection => {
 | 
			
		||||
        // nothing to do
 | 
			
		||||
      }}
 | 
			
		||||
    />
 | 
			
		||||
  ));
 | 
			
		||||
 
 | 
			
		||||
@@ -36,6 +36,11 @@ type Props = {
 | 
			
		||||
class DropDown extends React.Component<Props> {
 | 
			
		||||
  render() {
 | 
			
		||||
    const { options, optionValues, preselectedOption, className, disabled } = this.props;
 | 
			
		||||
 | 
			
		||||
    if (preselectedOption && options.filter(o => o === preselectedOption).length === 0) {
 | 
			
		||||
      options.push(preselectedOption);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return (
 | 
			
		||||
      <div className={classNames(className, "select", disabled ? "disabled" : "")}>
 | 
			
		||||
        <select value={preselectedOption ? preselectedOption : ""} onChange={this.change} disabled={disabled}>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user