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

fix: keep highlight on item with the menu open #4835

Merged
merged 17 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
d8e7505
Update projectTemplates.ts
beyackle Nov 6, 2020
cbbdba8
Merge branch 'main' of https://github.com/microsoft/BotFramework-Comp…
beyackle Nov 6, 2020
74c7daa
Merge branch 'main' of https://github.com/microsoft/BotFramework-Comp…
beyackle Nov 6, 2020
f7d7f0a
Merge branch 'main' of https://github.com/microsoft/BotFramework-Comp…
beyackle Nov 9, 2020
2a0ef2d
Merge branch 'main' of https://github.com/microsoft/BotFramework-Comp…
beyackle Nov 9, 2020
f8d96e2
Merge branch 'main' into feature/bot-projects
beyackle Nov 9, 2020
02abae4
Merge branch 'feature/bot-projects' of https://github.com/microsoft/B…
beyackle Nov 10, 2020
9b501af
Merge branch 'feature/bot-projects' of https://github.com/microsoft/B…
beyackle Nov 12, 2020
27e9bfd
Update navigation.test.tsx
beyackle Nov 12, 2020
89a7f2e
Merge branch 'feature/bot-projects' of https://github.com/microsoft/B…
beyackle Nov 13, 2020
f280f1e
Merge branch 'feature/bot-projects' of https://github.com/microsoft/B…
beyackle Nov 13, 2020
b080775
Merge branch 'feature/bot-projects' of https://github.com/microsoft/B…
beyackle Nov 16, 2020
8be2014
Merge branch 'feature/bot-projects' of https://github.com/microsoft/B…
beyackle Nov 16, 2020
3f2e251
add logic for new highlighting with menu open
beyackle Nov 16, 2020
ddbf156
fix color logic
beyackle Nov 17, 2020
ef09a03
Merge branch 'feature/bot-projects' into beyackle/keepFocusWithMenu
beyackle Nov 17, 2020
8ed05a3
Merge branch 'feature/bot-projects' into beyackle/keepFocusWithMenu
beyackle Nov 17, 2020
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
Expand Up @@ -185,6 +185,7 @@ export const ProjectTree: React.FC<Props> = ({
setPageElementState('design', { ...pageElements, [name]: value });

const [filter, setFilter] = useState('');
const [isMenuOpen, setMenuOpen] = useState<boolean>(false);
const formDialogComposerFeatureEnabled = useFeatureFlag('FORM_DIALOG');
const [selectedLink, setSelectedLink] = useState<Partial<TreeLink> | undefined>(defaultSelected);
const delayedSetFilter = throttle((newValue) => setFilter(newValue), 200);
Expand Down Expand Up @@ -328,8 +329,10 @@ export const ProjectTree: React.FC<Props> = ({
hasChildren={!bot.isRemote}
icon={bot.isRemote ? icons.EXTERNAL_SKILL : icons.BOT}
isActive={doesLinkMatch(link, selectedLink)}
isMenuOpen={isMenuOpen}
link={link}
menu={menu}
menuOpenCallback={setMenuOpen}
textWidth={leftSplitWidth - TREE_PADDING}
onSelect={handleOnSelect}
/>
Expand Down Expand Up @@ -398,8 +401,10 @@ export const ProjectTree: React.FC<Props> = ({
showProps
icon={isFormDialog ? icons.FORM_DIALOG : icons.DIALOG}
isActive={doesLinkMatch(dialogLink, selectedLink)}
isMenuOpen={isMenuOpen}
link={dialogLink}
menu={menu}
menuOpenCallback={setMenuOpen}
textWidth={leftSplitWidth - TREE_PADDING}
onSelect={handleOnSelect}
/>
Expand Down Expand Up @@ -434,6 +439,7 @@ export const ProjectTree: React.FC<Props> = ({
extraSpace={INDENT_PER_LEVEL}
icon={icons.TRIGGER}
isActive={doesLinkMatch(link, selectedLink)}
isMenuOpen={isMenuOpen}
link={link}
menu={[
{
Expand All @@ -444,6 +450,7 @@ export const ProjectTree: React.FC<Props> = ({
},
},
]}
menuOpenCallback={setMenuOpen}
textWidth={leftSplitWidth - TREE_PADDING}
onSelect={handleOnSelect}
/>
Expand Down Expand Up @@ -502,7 +509,14 @@ export const ProjectTree: React.FC<Props> = ({
`}
role="grid"
>
<TreeItem showProps isSubItemActive={false} link={link} textWidth={leftSplitWidth - TREE_PADDING} />
<TreeItem
showProps
isMenuOpen={isMenuOpen}
isSubItemActive={false}
link={link}
menuOpenCallback={setMenuOpen}
textWidth={leftSplitWidth - TREE_PADDING}
/>
</span>
);
};
Expand Down Expand Up @@ -651,7 +665,9 @@ export const ProjectTree: React.FC<Props> = ({
{onAllSelected != null ? (
<TreeItem
hasChildren={false}
isMenuOpen={isMenuOpen}
link={{ displayName: formatMessage('All'), projectId: rootProjectId, isRoot: true, diagnostics: [] }}
menuOpenCallback={setMenuOpen}
textWidth={leftSplitWidth - TREE_PADDING}
onSelect={onAllSelected}
/>
Expand Down
47 changes: 35 additions & 12 deletions Composer/packages/client/src/components/ProjectTree/treeItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/** @jsx jsx */
import { jsx, css } from '@emotion/core';
import React from 'react';
import React, { useState } from 'react';
import { FontWeights } from '@uifabric/styling';
import { FontSizes } from '@uifabric/fluent-theme';
import { OverflowSet, IOverflowSetItemProps } from 'office-ui-fabric-react/lib/OverflowSet';
Expand Down Expand Up @@ -79,29 +79,31 @@ export const moreButton = (isActive: boolean): IButtonStyles => {
};
};

const navItem = (isActive: boolean, isBroken: boolean) => css`
const navItem = (isActive: boolean, isBroken: boolean, isAnyMenuOpen: boolean, menuOpenHere: boolean) => css`
label: navItem;
min-width: 100%;
position: relative;
height: 24px;
font-size: 12px;
color: ${isActive ? NeutralColors.white : '#545454'};
background: ${isActive ? '#0078d4' : 'transparent'};
color: ${isActive && !menuOpenHere ? NeutralColors.white : '#545454'};
background: ${isActive ? '#0078d4' : menuOpenHere ? '#f2f2f2' : 'transparent'};
opacity: ${isBroken ? 0.5 : 1};
font-weight: ${isActive ? FontWeights.semibold : FontWeights.regular};

display: flex;
flex-direction: row;
align-items: center;

&:hover {
${isAnyMenuOpen
? ''
: `&:hover {
color: #545454;
background: #f2f2f2;

.dialog-more-btn {
visibility: visible;
}
}
}`}

&:focus {
outline: none;
Expand Down Expand Up @@ -205,6 +207,8 @@ interface ITreeItemProps {
textWidth?: number;
extraSpace?: number;
hasChildren?: boolean;
menuOpenCallback?: (boolean) => void;
isMenuOpen?: boolean;
}

const renderTreeMenuItem = (link: TreeLink) => (item: TreeMenuItem) => {
Expand All @@ -229,7 +233,7 @@ const renderTreeMenuItem = (link: TreeLink) => (item: TreeMenuItem) => {
};
};

const onRenderItem = (textWidth: number) => (item: IOverflowSetItemProps) => {
const onRenderItem = (textWidth: number, isMenuOpen: boolean) => (item: IOverflowSetItemProps) => {
const { diagnostics = [] } = item;
const warnings: Diagnostic[] = diagnostics.filter((diag) => diag.severity === DiagnosticSeverity.Warning);
const errors: Diagnostic[] = diagnostics.filter((diag) => diag.severity === DiagnosticSeverity.Error);
Expand Down Expand Up @@ -310,7 +314,11 @@ const onRenderItem = (textWidth: number) => (item: IOverflowSetItemProps) => {
);
};

const onRenderOverflowButton = (isActive: boolean) => {
const onRenderOverflowButton = (
isActive: boolean,
menuOpenCallback: (boolean) => void,
setThisItemSelected: (boolean) => void
) => {
const moreLabel = formatMessage('Actions');
return (overflowItems: IContextualMenuItem[] | undefined) => {
if (overflowItems == null) return null;
Expand All @@ -322,7 +330,18 @@ const onRenderOverflowButton = (isActive: boolean) => {
data-is-focusable={isActive}
data-testid="dialogMoreButton"
menuIconProps={{ iconName: 'MoreVertical' }}
menuProps={{ items: overflowItems, styles: menuStyle }}
menuProps={{
items: overflowItems,
styles: menuStyle,
onMenuOpened: () => {
setThisItemSelected(true);
menuOpenCallback(true);
},
onMenuDismissed: () => {
setThisItemSelected(false);
menuOpenCallback(false);
},
}}
role="cell"
styles={moreButton(isActive)}
onKeyDown={(e) => {
Expand All @@ -346,7 +365,11 @@ export const TreeItem: React.FC<ITreeItemProps> = ({
hasChildren = false,
menu = [],
extraSpace = 0,
menuOpenCallback = () => {},
isMenuOpen = false,
}) => {
const [thisItemSelected, setThisItemSelected] = useState<boolean>(false);

const a11yLabel = `${dialogName ?? '$Root'}_${link.displayName}`;

const overflowMenu = menu.map(renderTreeMenuItem(link));
Expand All @@ -358,7 +381,7 @@ export const TreeItem: React.FC<ITreeItemProps> = ({
return (
<div
aria-label={a11yLabel}
css={navItem(isActive, isBroken)}
css={navItem(isActive, isBroken, isMenuOpen, thisItemSelected)}
data-testid={a11yLabel}
role="gridcell"
tabIndex={0}
Expand Down Expand Up @@ -388,8 +411,8 @@ export const TreeItem: React.FC<ITreeItemProps> = ({
overflowItems={overflowMenu}
role="row"
styles={{ item: { flex: 1 } }}
onRenderItem={onRenderItem(textWidth - spacerWidth + extraSpace)}
onRenderOverflowButton={onRenderOverflowButton(!!isActive)}
onRenderItem={onRenderItem(textWidth - spacerWidth + extraSpace, isMenuOpen)}
onRenderOverflowButton={onRenderOverflowButton(!!isActive, menuOpenCallback, setThisItemSelected)}
/>
</div>
);
Expand Down