UNPKG

react-native-accessibility-engine

Version:

Make accessibility-related assertions on React Native code using React Test Renderer

45 lines (36 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _helpers = require("../../helpers"); var _reactNative = require("react-native"); const rule = { id: 'pressable-label-required', matcher: node => (0, _helpers.isPressable)(node.type), assertion: node => { var _textNode$props; const textNode = getTextNode(node); const textContent = textNode === null || textNode === void 0 ? void 0 : (_textNode$props = textNode.props) === null || _textNode$props === void 0 ? void 0 : _textNode$props.children; const accessibilityLabel = node.props.accessibilityLabel; if (!accessibilityLabel && !textContent) { return false; } return true; }, help: { problem: "This pressable has no text content, so an accessibility label can't be automatically inferred", solution: "Place a text component in the button or define an 'accessibilityLabel' prop", link: '' } }; const getTextNode = node => { try { return node.findByType(_reactNative.Text); } catch (e) { return null; } }; var _default = rule; exports.default = _default; //# sourceMappingURL=index.js.map