chore: new arrow key navigation (#3229)

* rebuild keyboard navigation lists
* add new keyboard navigation components
* remove references to boundless-arrow-key-navigation
* fix aria-labels on paginated lists everywhere
This commit is contained in:
Nan Yu
2022-03-15 10:36:10 -07:00
committed by GitHub
parent 093158cb11
commit d1b28499c6
18 changed files with 270 additions and 112 deletions

View File

@@ -8,18 +8,19 @@ type Props = React.HTMLAttributes<HTMLInputElement> & {
placeholder?: string;
};
function SearchInput({ defaultValue, ...rest }: Props) {
function SearchInput(
{ defaultValue, ...rest }: Props,
ref: React.RefObject<HTMLInputElement>
) {
const theme = useTheme();
const inputRef = React.useRef<HTMLInputElement>(null);
const focusInput = React.useCallback(() => {
inputRef.current?.focus();
}, []);
ref.current?.focus();
}, [ref]);
React.useEffect(() => {
// ensure that focus is placed at end of input
const len = (defaultValue || "").length;
inputRef.current?.setSelectionRange(len, len);
ref.current?.setSelectionRange(len, len);
const timeoutId = setTimeout(() => {
focusInput();
}, 100); // arbitrary number
@@ -27,7 +28,7 @@ function SearchInput({ defaultValue, ...rest }: Props) {
return () => {
clearTimeout(timeoutId);
};
}, [defaultValue, focusInput]);
}, [ref, defaultValue, focusInput]);
return (
<Wrapper align="center">
@@ -35,7 +36,7 @@ function SearchInput({ defaultValue, ...rest }: Props) {
<StyledInput
{...rest}
defaultValue={defaultValue}
ref={inputRef}
ref={ref}
spellCheck="false"
type="search"
autoFocus
@@ -84,4 +85,4 @@ const StyledIcon = styled(SearchIcon)`
left: 8px;
`;
export default SearchInput;
export default React.forwardRef(SearchInput);