office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
71 lines • 3.66 kB
JavaScript
define(["require", "exports", "tslib", "../../Utilities", "../../utilities/keytips/KeytipManager", "../../utilities/keytips/KeytipUtils"], function (require, exports, tslib_1, Utilities_1, KeytipManager_1, KeytipUtils_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* 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_1.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 = KeytipUtils_1.getAriaDescribedBy(newKeytipProps.keySequences);
var keySequences = newKeytipProps.keySequences.slice();
if (newKeytipProps.overflowSetSequence) {
keySequences = KeytipUtils_1.mergeOverflows(keySequences, newKeytipProps.overflowSetSequence);
}
var ktpId = KeytipUtils_1.sequencesToID(keySequences);
return {
'aria-describedby': Utilities_1.mergeAriaAttributeValues(describedByPrepend, ariaDescribedBy),
'data-ktp-target': ktpId,
'data-ktp-execute-target': ktpId
};
}
return undefined;
};
return KeytipData;
}(Utilities_1.BaseComponent));
exports.KeytipData = KeytipData;
});
//# sourceMappingURL=KeytipData.js.map