Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReAdd: Keytips: Align keytipData with visible instance for dupes #28992

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Keytip: Make keytip data align with which instance is visible (for duplicate registrations)",
"packageName": "@fluentui/react",
"email": "jspurlin@microsoft.com",
"dependentChangeType": "patch"
}
16 changes: 15 additions & 1 deletion packages/react/src/components/KeytipLayer/KeytipLayer.base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Async,
initializeComponentRef,
KeyCodes,
isElementVisibleAndNotHidden,
} from '../../Utilities';
import { KeytipManager } from '../../utilities/keytips/KeytipManager';
import { KeytipTree } from './KeytipTree';
Expand Down Expand Up @@ -376,10 +377,23 @@ export class KeytipLayerBase extends React.Component<IKeytipLayerProps, IKeytipL
keytipId = sequencesToID(mergeOverflows(keytip.keySequences, keytip.overflowSetSequence));
}
seenIds[keytipId] = seenIds[keytipId] ? seenIds[keytipId] + 1 : 1;
return keytip.visible && seenIds[keytipId] === 1;

// Return true only if the keytip is visible and the corresponding target is also visible
return keytip.visible && this._isKeytipInstanceTargetVisible(keytip.keySequences, seenIds[keytipId]);
});
}

private _isKeytipInstanceTargetVisible = (keySequences: string[], instanceCount: number): boolean => {
const targetSelector = ktpTargetFromSequences(keySequences);
const matchingElements = document.querySelectorAll(targetSelector);

// If there are multiple elements for the keytip sequence, return true if the element instance
// that corresponds to the keytip instance is visible, otherwise return if there is only one instance
return matchingElements.length > 1 && instanceCount <= matchingElements.length
? isElementVisibleAndNotHidden(matchingElements[instanceCount - 1] as HTMLElement)
: instanceCount === 1;
};

private _onDismiss = (ev?: React.MouseEvent<HTMLElement>): void => {
// if we are in keytip mode, then exit keytip mode
if (this.state.inKeytipMode) {
Expand Down