MCPcopy Create free account
hub / github.com/microsoft/SandDance / useKeytipData

Function useKeytipData

docs/app/js/sanddance-app.js:34402–34430  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

34400var _utilities = require("../../Utilities");
34401var _index = require("../../utilities/keytips/index");
34402function useKeytipData(options) {
34403 var uniqueId = _react.useRef();
34404 var keytipProps = options.keytipProps ? (0, _tslib.__assign)({
34405 disabled: options.disabled
34406 }, options.keytipProps) : undefined;
34407 var keytipManager = (0, _reactHooks.useConst)((0, _index.KeytipManager).getInstance());
34408 var prevOptions = (0, _reactHooks.usePrevious)(options);
34409 // useLayoutEffect used to strictly emulate didUpdate/didMount behavior
34410 _react.useLayoutEffect(function() {
34411 var _a, _b;
34412 if (uniqueId.current && keytipProps && (((_a = prevOptions) === null || _a === void 0 ? void 0 : _a.keytipProps) !== options.keytipProps || ((_b = prevOptions) === null || _b === void 0 ? void 0 : _b.disabled) !== options.disabled)) keytipManager.update(keytipProps, uniqueId.current);
34413 });
34414 _react.useLayoutEffect(function() {
34415 // Register Keytip in KeytipManager
34416 if (keytipProps) uniqueId.current = keytipManager.register(keytipProps);
34417 return function() {
34418 // Unregister Keytip in KeytipManager
34419 keytipProps && keytipManager.unregister(keytipProps, uniqueId.current);
34420 };
34421 // this is meant to run only at mount, and updates are handled separately
34422 // eslint-disable-next-line react-hooks/exhaustive-deps
34423 }, []);
34424 var nativeKeytipProps = {
34425 ariaDescribedBy: undefined,
34426 keytipId: undefined
34427 };
34428 if (keytipProps) nativeKeytipProps = getKeytipData(keytipManager, keytipProps, options.ariaDescribedBy);
34429 return nativeKeytipProps;
34430}
34431/**
34432 * Gets the aria- and data- attributes to attach to the component
34433 * @param keytipProps - options for Keytip

Callers

nothing calls this directly

Calls 2

getKeytipDataFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected