@enact/ui
Version:
A collection of simplified unstyled cross-platform UI components for Enact
53 lines (51 loc) • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
exports.useAnnounce = useAnnounce;
var _react = require("react");
var _Announce = _interopRequireDefault(require("./Announce"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* Object returned by `useAnnounce`
*
* @typedef {Object} useAnnounceInterface
* @property {Function} announce Called to alert the user of behavior for accessibility
* @property {Node} children An additional element which must be added to the component tree to
* support notifying the user
* @private
*/
/**
* Provides a method to alert the user of behavior for accessibility.
*
* ```
* function Component () {
* const {announce, children} = useAnnounce();
*
* return (
* <Base onClick={() => announce('Unusually important notification for accessibility')}>
* {children}
* </Base>
* );
* }
* ```
*
* @returns {useAnnounceInterface}
* @private
*/function useAnnounce() {
var ref = (0, _react.useRef)(null);
var announce = (0, _react.useCallback)(function (message) {
if (ref.current) {
ref.current.announce(message);
}
}, [ref]);
return {
announce: announce,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Announce["default"], {
ref: ref
})
};
}
var _default = exports["default"] = useAnnounce;