UNPKG

react-native-a11y-order

Version:

ReactNative library for managing screen reader focus ordering

33 lines 1.51 kB
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } import React, { useImperativeHandle, useRef } from 'react'; import { A11ySequenceOrderContext } from '../../context/A11ySequenceOrderContext'; import A11yIndexView, { Commands } from '../../nativeSpecs/A11yIndexNativeComponent'; import { A11yOrderTypeEnum } from '../../types/A11yIndex.types'; export const A11yIndex = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef(({ children, index, orderType = 'default', ...props }, ref) => { const orderKey = React.useContext(A11ySequenceOrderContext); if (!orderKey) { throw new Error('<A11y.Index> element should be used inside of <A11y.Order> container'); } const indexRef = useRef(null); useImperativeHandle(ref, () => ({ focus: () => { if (indexRef.current) { Commands.focus(indexRef.current); } } })); const importantForAccessibility = orderType === 'default' ? 'yes' : undefined; return /*#__PURE__*/React.createElement(A11yIndexView, _extends({ importantForAccessibility: props.importantForAccessibility ?? importantForAccessibility, orderFocusType: A11yOrderTypeEnum[orderType], ref: indexRef, orderIndex: index, orderKey: orderKey }, props), children); })); //# sourceMappingURL=A11yIndex.js.map