-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Update keytip functionality #20396
Merged
jspurlin
merged 19 commits into
microsoft:master
from
jspurlin:jspurlin/UpdateKeytipFunctionality
Nov 2, 2021
Merged
Update keytip functionality #20396
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
68fffc2
Make callouts aware of the WindowSegments
jspurlin bfd68c1
Revert "Make callouts aware of the WindowSegments"
jspurlin 5d89c48
Merge branch 'master' of https://github.com/OfficeDev/office-ui-fabri…
jspurlin 297ccfb
Merge branch 'master' of https://github.com/OfficeDev/office-ui-fabri…
jspurlin b0a90af
Merge branch 'master' of https://github.com/OfficeDev/office-ui-fabri…
jspurlin f84ee51
Merge branch 'master' of https://github.com/OfficeDev/office-ui-fabri…
jspurlin 4a22530
Merge branch 'master' of http://github.com/microsoft/fluentui
jspurlin 60042cd
Merge branch 'master' of http://github.com/microsoft/fluentui
jspurlin 06343aa
Merge branch 'master' of https://github.com/microsoft/fluentui
jspurlin af21a19
Merge branch 'master' of http://github.com/microsoft/fluentui
jspurlin 955cfc4
Merge branch 'microsoft:master' into master
jspurlin 3843732
Merge branch 'master' of http://github.com/microsoft/fluentui
jspurlin 2b16965
Keytips: Make keytips aware of the visibility of their targets
jspurlin a02945f
Change files
jspurlin fcc3b3e
Fix the lint errors
jspurlin 6865f1f
Update keytip story
jspurlin debb6c9
Actually update the story to use a DefaultButton instead of an html b…
jspurlin ffdc5ad
actually I just noticed there was already a ktp target span, undoing …
jspurlin ee9d3c2
Update story because js was executing before first paint causing keyt…
jspurlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-9c097d21-6944-4b2a-b35f-09bf82daa408.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Keytips: Make keytips aware of the visibility of their targets", | ||
"packageName": "@fluentui/react", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-utilities-dfe0019e-0dd3-4f0b-b462-ffd253a88cfb.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Add isElementVisibleAndNotHidden utility function", | ||
"packageName": "@fluentui/utilities", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||
import { find, values } from '../../Utilities'; | ||||||
import { mergeOverflows, sequencesToID } from '../../utilities/keytips/KeytipUtils'; | ||||||
import { find, isElementVisibleAndNotHidden, values } from '../../Utilities'; | ||||||
import { ktpTargetFromSequences, mergeOverflows, sequencesToID } from '../../utilities/keytips/KeytipUtils'; | ||||||
import { KTP_LAYER_ID } from '../../utilities/keytips/KeytipConstants'; | ||||||
import type { IKeytipProps } from '../../Keytip'; | ||||||
import type { IKeytipTreeNode } from './IKeytipTreeNode'; | ||||||
|
@@ -126,9 +126,52 @@ export class KeytipTree { | |||||
*/ | ||||||
public getExactMatchedNode(keySequence: string, currentKeytip: IKeytipTreeNode): IKeytipTreeNode | undefined { | ||||||
const possibleNodes = this.getNodes(currentKeytip.children); | ||||||
return find(possibleNodes, (node: IKeytipTreeNode) => { | ||||||
const matchingNodes = possibleNodes.filter((node: IKeytipTreeNode) => { | ||||||
return this._getNodeSequence(node) === keySequence && !node.disabled; | ||||||
}); | ||||||
|
||||||
// If we found no nodes, we are done | ||||||
if (matchingNodes.length === 0) { | ||||||
return undefined; | ||||||
} | ||||||
|
||||||
// Since the matching nodes all have the same key sequence, | ||||||
// Grab the first one build the correct selector | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
const node = matchingNodes[0]; | ||||||
|
||||||
// If we have exactly one node, return it | ||||||
if (matchingNodes.length === 1) { | ||||||
return node; | ||||||
} | ||||||
|
||||||
// Get the potential target elements based on a selector from the sequences | ||||||
const keySequences = node.keySequences; | ||||||
const overflowSetSequence = node.overflowSetSequence; | ||||||
const fullKeySequences = overflowSetSequence ? mergeOverflows(keySequences, overflowSetSequence) : keySequences; | ||||||
const keytipTargetSelector = ktpTargetFromSequences(fullKeySequences); | ||||||
const potentialTargetElements = document.querySelectorAll(keytipTargetSelector); | ||||||
|
||||||
// If we have less nodes than the potential target elements, | ||||||
// we won't be able to map element to node, return the first node. | ||||||
// Note, the number of nodes could be more than the number of potential | ||||||
// target elements, if an OverflowSet is involved | ||||||
if (matchingNodes.length < potentialTargetElements.length) { | ||||||
return node; | ||||||
} | ||||||
|
||||||
// Attempt to find the node that corresponds to the first visible/non-hidden element | ||||||
const matchingIndex = Array.from(potentialTargetElements).findIndex((element: HTMLElement) => | ||||||
isElementVisibleAndNotHidden(element), | ||||||
); | ||||||
if (matchingIndex !== -1) { | ||||||
return matchingNodes[matchingIndex]; | ||||||
} | ||||||
|
||||||
// We did not find any visible elements associated with any of the nodes. | ||||||
// We may be dealing with a keytip that is a submenu in an OverflowSet. | ||||||
// Worst case, fall back to the first node returned | ||||||
const overflowNode = matchingNodes.find(matchingNode => matchingNode.hasOverflowSubMenu); | ||||||
return overflowNode || node; | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -259,6 +302,7 @@ export class KeytipTree { | |||||
onExecute, | ||||||
onReturn, | ||||||
disabled, | ||||||
hasOverflowSubMenu, | ||||||
} = keytipProps; | ||||||
const node = { | ||||||
id, | ||||||
|
@@ -272,6 +316,7 @@ export class KeytipTree { | |||||
hasMenu, | ||||||
disabled, | ||||||
persisted, | ||||||
hasOverflowSubMenu, | ||||||
}; | ||||||
node.children = Object.keys(this.nodeMap).reduce((array: string[], nodeMapKey: string): string[] => { | ||||||
if (this.nodeMap[nodeMapKey].parent === id) { | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/utilities/src/dom/getFirstVisibleElementFromSelector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { isElementVisibleAndNotHidden } from '../focus'; | ||
import { getDocument } from './getDocument'; | ||
|
||
/** | ||
* Gets the first visible element that matches the given selector | ||
* @param selector - The selector to use to find potential visible elements | ||
* @returns The first visible element that matches the selector, otherwise undefined | ||
* | ||
* @public | ||
*/ | ||
export function getFirstVisibleElementFromSelector(selector: string): Element | undefined { | ||
const elements = getDocument()!.querySelectorAll(selector); | ||
|
||
// Iterate across the elements that match the selector and return the first visible/non-hidden element | ||
return Array.from(elements).find((element: HTMLElement) => isElementVisibleAndNotHidden(element)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: