1import React, { useCallback, useRef, useState } from 'react';
2import cn from 'classnames';
4import Flex from './Flex';
5import { ErrorText } from './Typography';
6import useOnClickOutside from 'indigo-react/lib/useOnClickOutside';
7import AccessoryIcon from './AccessoryIcon';
9// NOTE: if we really care about accessibility, we should pull in a dependency
10export default function SelectInput({
43 const [isOpen, setIsOpen] = useState(false);
46 // close select on outside clicks
47 useOnClickOutside(ref, useCallback(() => setIsOpen(false), [setIsOpen]));
49 const toggleOpen = useCallback(() => setIsOpen(isOpen => !isOpen), [
53 const onChange = value => {
54 // TODO: provide setValue here?
55 // construct a pseudo event that sets the value correctly
56 bind.onChange({ target: { value } });
60 // redefine accessory because we still want to ignore it from the ..rest above
62 <AccessoryIcon className="gray4">{isOpen ? '▲' : '▼'}</AccessoryIcon>
65 const text = options.find(o => o.value === data).text;
70 className={cn(className, 'mb1 us-none')}
74 pointerEvents: 'none',
75 cursor: 'not-allowed',
78 <Flex.Item as="label" className="f6 lh-tall" htmlFor={name}>
81 <Flex.Item as={Flex} row className="rel clickable" onClick={toggleOpen}>
85 'b b1 p3 outline-none',
88 'bg-white': !disabled,
96 'b-green3': visiblyPassed,
97 'b-black': focused && !visiblyPassed,
98 'b-yellow3': !focused && hintError,
99 'b-gray3': !focused && !hintError && !visiblyPassed,
106 {isOpen ? placeholder : text}
122 className="abs bg-white b-black b1 z10"
124 top: 'calc(100% + 4px)',
130 {options.map(option => (
133 className="pv2 ph3 hover-bg-grey3"
136 onChange(option.value);
145 <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