UNPKG

@fluentui/react

Version:

Reusable React components for building web experiences.

68 lines 2.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sequencesToID = sequencesToID; exports.mergeOverflows = mergeOverflows; exports.ktpTargetFromSequences = ktpTargetFromSequences; exports.ktpTargetFromId = ktpTargetFromId; exports.getAriaDescribedBy = getAriaDescribedBy; var tslib_1 = require("tslib"); var KeytipConstants_1 = require("./KeytipConstants"); var Utilities_1 = require("../../Utilities"); /** * Converts a whole set of KeySequences into one keytip ID, which will be the ID for the last keytip sequence specified * keySequences should not include the initial keytip 'start' sequence. * * @param keySequences - Full path of IKeySequences for one keytip. * @returns String to use for the keytip ID. */ function sequencesToID(keySequences) { return keySequences.reduce(function (prevValue, keySequence) { return prevValue + KeytipConstants_1.KTP_SEPARATOR + keySequence.split('').join(KeytipConstants_1.KTP_SEPARATOR); }, KeytipConstants_1.KTP_PREFIX); } /** * Merges an overflow sequence with a key sequence. * * @param keySequences - Full sequence for one keytip. * @param overflowKeySequences - Full overflow keytip sequence. * @returns Sequence that will be used by the keytip when in the overflow. */ function mergeOverflows(keySequences, overflowKeySequences) { var overflowSequenceLen = overflowKeySequences.length; var overflowSequence = tslib_1.__spreadArray([], overflowKeySequences, true).pop(); var newKeySequences = tslib_1.__spreadArray([], keySequences, true); return (0, Utilities_1.addElementAtIndex)(newKeySequences, overflowSequenceLen - 1, overflowSequence); } /** * Constructs the data-ktp-target attribute selector from a full key sequence. * * @param keySequences - Full string[] for a Keytip. * @returns String selector to use to query for the keytip target. */ function ktpTargetFromSequences(keySequences) { return '[' + KeytipConstants_1.DATAKTP_TARGET + '="' + sequencesToID(keySequences) + '"]'; } /** * Constructs the data-ktp-execute-target attribute selector from a keytip ID. * * @param keytipId - ID of the Keytip. * @returns String selector to use to query for the keytip execute target. */ function ktpTargetFromId(keytipId) { return '[' + KeytipConstants_1.DATAKTP_EXECUTE_TARGET + '="' + keytipId + '"]'; } /** * Gets the aria-describedby value to put on the component with this keytip. * * @param keySequences - KeySequences of the keytip. * @returns The aria-describedby value to set on the component with this keytip. */ function getAriaDescribedBy(keySequences) { var describedby = ' ' + KeytipConstants_1.KTP_LAYER_ID; if (!keySequences.length) { // Return just the layer ID return describedby; } return describedby + ' ' + sequencesToID(keySequences); } //# sourceMappingURL=KeytipUtils.js.map