Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
feat(FormSelect): add missing props
Browse files Browse the repository at this point in the history
Adds various props that are found on other input components but were
missing here, including onBlur, name, value and error
  • Loading branch information
jonthomp committed May 31, 2018
1 parent 89e1e9e commit ee57c54
Showing 1 changed file with 61 additions and 6 deletions.
67 changes: 61 additions & 6 deletions src/components/Form/FormSelect.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,78 @@

import * as React from "react";
import cn from "classnames";
import FormGroup from "./FormGroup.react";

type Props = {|
+children?: React.Node,
+className?: string,
+onChange?: (SyntheticInputEvent<EventTarget>) => mixed,
+onBlur?: (SyntheticInputEvent<EventTarget>) => mixed,
+valid?: boolean,
+tick?: boolean,
+invalid?: boolean,
+cross?: boolean,
+feedback?: string,
+error?: string,
/**
* Wraps the select in Form.Group and adds a label
*/
+label?: string,
+name?: string,
+value?: string | number,
+disabled?: boolean,
+readOnly?: boolean,
|};

function FormSelect({ className, children, onChange }: Props): React.Node {
function FormSelect(props: Props): React.Node {
const {
className,
children,
onChange,
valid,
tick,
invalid,
cross,
error,
label,
onBlur,
disabled,
readOnly,
name,
value,
} = props;
const classes = cn(
{ "form-control": true, "custom-select": true },
{
"form-control": true,
"custom-select": true,
"is-valid": valid,
"state-valid": tick,
"is-invalid": invalid || !!error,
"state-invalid": cross || !!error,
},
className
);
return (
<select onChange={onChange} className={classes}>
{children}
</select>

const feedback = error || props.feedback;

const contents = (
<React.Fragment>
<select
name={name}
value={value}
onChange={onChange}
onBlur={onBlur}
className={classes}
disabled={disabled}
readOnly={readOnly}
>
{children}
</select>
{feedback && <span className="invalid-feedback">{feedback}</span>}
</React.Fragment>
);

return label ? <FormGroup label={label}>{contents}</FormGroup> : contents;
}

FormSelect.displayName = "Form.Select";
Expand Down

0 comments on commit ee57c54

Please sign in to comment.