UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

71 lines 3.28 kB
import * as tslib_1 from "tslib"; import { BaseComponent, mergeAriaAttributeValues } from '../../Utilities'; import { KeytipManager } from '../../utilities/keytips/KeytipManager'; import { mergeOverflows, sequencesToID, getAriaDescribedBy } from '../../utilities/keytips/KeytipUtils'; /** * A small element to help the target component correctly read out its aria-describedby for its Keytip * * @export * @class KeytipData * @extends {BaseComponent<IKeytipDataProps & IRenderComponent<{}>, {}>} */ var KeytipData = /** @class */ (function (_super) { tslib_1.__extends(KeytipData, _super); function KeytipData() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._keytipManager = KeytipManager.getInstance(); return _this; } KeytipData.prototype.componentDidMount = function () { // Register Keytip in KeytipManager if (this.props.keytipProps) { this._uniqueId = this._keytipManager.register(this._getKtpProps()); } }; KeytipData.prototype.componentWillUnmount = function () { // Unregister Keytip in KeytipManager this.props.keytipProps && this._keytipManager.unregister(this._getKtpProps(), this._uniqueId); }; KeytipData.prototype.componentDidUpdate = function () { // Update Keytip in KeytipManager this.props.keytipProps && this._keytipManager.update(this._getKtpProps(), this._uniqueId); }; KeytipData.prototype.render = function () { var _a = this.props, children = _a.children, keytipProps = _a.keytipProps, ariaDescribedBy = _a.ariaDescribedBy; var nativeKeytipProps = {}; if (keytipProps) { nativeKeytipProps = this._getKtpAttrs(keytipProps, ariaDescribedBy); } return children(nativeKeytipProps); }; KeytipData.prototype._getKtpProps = function () { return tslib_1.__assign({ disabled: this.props.disabled }, this.props.keytipProps); }; /** * Gets the aria- and data- attributes to attach to the component * @param keytipProps * @param describedByPrepend */ KeytipData.prototype._getKtpAttrs = function (keytipProps, describedByPrepend) { if (keytipProps) { // Add the parent overflow sequence if necessary var newKeytipProps = this._keytipManager.addParentOverflow(keytipProps); // Construct aria-describedby and data-ktp-id attributes and return var ariaDescribedBy = getAriaDescribedBy(newKeytipProps.keySequences); var keySequences = newKeytipProps.keySequences.slice(); if (newKeytipProps.overflowSetSequence) { keySequences = mergeOverflows(keySequences, newKeytipProps.overflowSetSequence); } var ktpId = sequencesToID(keySequences); return { 'aria-describedby': mergeAriaAttributeValues(describedByPrepend, ariaDescribedBy), 'data-ktp-target': ktpId, 'data-ktp-execute-target': ktpId }; } return undefined; }; return KeytipData; }(BaseComponent)); export { KeytipData }; //# sourceMappingURL=KeytipData.js.map