2020-07-15 04:22:19 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2020-07-15 04:26:10 +01:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2024-09-09 14:57:16 +01:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2020-07-15 04:26:10 +01:00
|
|
|
*/
|
2020-07-15 04:22:19 +01:00
|
|
|
|
2024-11-13 18:23:37 +05:30
|
|
|
import React, { ReactElement, RefCallback } from "react";
|
2020-07-15 04:22:19 +01:00
|
|
|
|
2021-06-29 13:11:58 +01:00
|
|
|
import { useRovingTabIndex } from "../RovingTabIndex";
|
|
|
|
|
import { FocusHandler, Ref } from "./types";
|
2020-07-15 04:22:19 +01:00
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
|
inputRef?: Ref;
|
2024-11-13 00:28:32 +05:30
|
|
|
children(renderProps: {
|
|
|
|
|
onFocus: FocusHandler;
|
|
|
|
|
isActive: boolean;
|
2024-11-13 18:23:37 +05:30
|
|
|
ref: RefCallback<HTMLElement>;
|
2024-11-13 00:28:32 +05:30
|
|
|
}): ReactElement<any, any>;
|
2020-07-15 04:22:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wrapper to allow use of useRovingTabIndex outside of React Functional Components.
|
2021-06-29 13:11:58 +01:00
|
|
|
export const RovingTabIndexWrapper: React.FC<IProps> = ({ children, inputRef }) => {
|
2020-07-15 04:22:19 +01:00
|
|
|
const [onFocus, isActive, ref] = useRovingTabIndex(inputRef);
|
2021-06-29 13:11:58 +01:00
|
|
|
return children({ onFocus, isActive, ref });
|
2020-07-15 04:22:19 +01:00
|
|
|
};
|