1import React, { useCallback, useRef, useState } from 'react';
2import cn from 'classnames';
3import { useField } from 'react-final-form';
4import useOnClickOutside from 'indigo-react/lib/useOnClickOutside';
6import Flex from './Flex';
7import { ErrorText } from './Typography';
8import AccessoryIcon from './AccessoryIcon';
10// NOTE: if we really care about accessibility, we should pull in a dependency
11export default function SelectInput({
23 meta: { active, error, submitting, submitSucceeded, touched, valid },
28 disabled = disabled || submitting || submitSucceeded;
30 const [isOpen, setIsOpen] = useState(false);
33 // close select on outside clicks
36 useCallback(() => setIsOpen(false), [setIsOpen])
39 const toggleOpen = useCallback(() => {
41 setIsOpen(isOpen => !isOpen);
44 const onChange = value => {
45 // construct a pseudo event that sets the value correctly
46 input.onChange({ target: { value } });
51 const text = options.find(o => o.value === input.value).text;
56 className={cn(className, 'mb1 us-none')}
60 pointerEvents: 'none',
61 cursor: 'not-allowed',
64 <Flex.Item as="label" className="f6 lh-tall" htmlFor={name}>
67 <Flex.Item as={Flex} row className="rel pointer" onClick={toggleOpen}>
71 'b b1 p3 outline-none',
74 'bg-white': !disabled,
83 'b-black': !valid && active,
84 'b-yellow3': !valid && !active && touched && error,
85 'b-gray2': !valid && !active && !touched && !error,
90 {isOpen ? placeholder : text}
101 <AccessoryIcon className="gray4">{isOpen ? '▲' : '▼'}</AccessoryIcon>
106 className="abs bg-white b-black b1 z10"
108 top: 'calc(100% + 4px)',
114 {options.map(option => (
117 className="pv2 ph3 hover-bg-grey3"
120 onChange(option.value);
130 <Flex.Item as={ErrorText} className="mv1">
135 {touched && !active && error && (
136 <Flex.Item as={ErrorText} className="mv1">
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list