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: Keyboard accessible context menus #1768

Merged
merged 34 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
708c563
Proof of concept, account menu
tommoor Jan 5, 2021
b338ef0
Merge branch 'develop' of github.com:outline/outline into fix/issue-1766
tommoor Jan 9, 2021
9bbad81
wip
tommoor Jan 9, 2021
e57d996
custom
tommoor Jan 9, 2021
cca8f1b
CollectionSortMenu
tommoor Jan 9, 2021
3c69be9
CollectionMenu
tommoor Jan 9, 2021
4d5839f
modal
tommoor Jan 10, 2021
fcc2414
feat: TemplateMenu
tommoor Jan 10, 2021
315850a
feat: ShareMenu
tommoor Jan 10, 2021
05f7421
feat: RevisionMenu
tommoor Jan 10, 2021
97620b5
lint
tommoor Jan 10, 2021
bc67aff
feat: DocumentMenu
tommoor Jan 11, 2021
eb684b3
feat: GroupMenu
tommoor Jan 11, 2021
20d3d57
feat: BreadcrumbMenu
tommoor Jan 11, 2021
5a681ca
fix: Restore onOpen,onClose callbacks
tommoor Jan 11, 2021
cda4dfa
feat: NewTemplateMenu
tommoor Jan 11, 2021
121fd8c
Remaining menus
tommoor Jan 11, 2021
ab72d3c
lint
tommoor Jan 11, 2021
53a227e
lint
tommoor Jan 11, 2021
7ffd193
fix: File upload should not be tabbable separate to menu
tommoor Jan 11, 2021
a6530fd
More fixes
tommoor Jan 11, 2021
76e6585
fix: Submenu rendering from template
tommoor Jan 11, 2021
33c1631
perf, header menu fixes
tommoor Jan 11, 2021
e892bb4
Merge develop
tommoor Jan 11, 2021
edba1da
lint
tommoor Jan 11, 2021
b50257e
Merge branch 'develop' of github.com:outline/outline into fix/issue-1766
tommoor Jan 12, 2021
3679a64
Perf: Delayed menu contents mount
tommoor Jan 12, 2021
f179b37
fix: Improve menu positioning on DocumentListItem
tommoor Jan 12, 2021
67f0754
fix: Cannot select search filter menu items with keyboard
tommoor Jan 12, 2021
2bf1b49
fix: Translation consistency, more minor layout issues
tommoor Jan 12, 2021
4cb81c3
flow
tommoor Jan 12, 2021
d7f86a0
fixes
tommoor Jan 12, 2021
851ee27
fix: Show 'Template' badge on search results
tommoor Jan 12, 2021
5580075
fix: ContextMenu onOpen/onClose callbacks called multiple times
tommoor Jan 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.file_ext=.json
esproposal.decorators=ignore
esproposal.class_static_fields=enable
esproposal.class_instance_fields=enable
esproposal.optional_chaining=enable

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue
5 changes: 0 additions & 5 deletions app/components/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ export const Action = styled(Flex)`
font-size: 15px;
flex-shrink: 0;

a {
color: ${(props) => props.theme.text};
height: 24px;
}

&:empty {
display: none;
}
Expand Down
36 changes: 13 additions & 23 deletions app/components/Breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
ArchiveIcon,
EditIcon,
GoToIcon,
MoreIcon,
PadlockIcon,
ShapesIcon,
TrashIcon,
Expand All @@ -14,18 +13,15 @@ import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";
import styled from "styled-components";
import breakpoint from "styled-components-breakpoint";

import CollectionsStore from "stores/CollectionsStore";
import Document from "models/Document";
import CollectionIcon from "components/CollectionIcon";
import Flex from "components/Flex";
import BreadcrumbMenu from "./BreadcrumbMenu";
import useStores from "hooks/useStores";
import BreadcrumbMenu from "menus/BreadcrumbMenu";
import { collectionUrl } from "utils/routeHelpers";

type Props = {
document: Document,
collections: CollectionsStore,
onlyText: boolean,
};

Expand Down Expand Up @@ -133,7 +129,7 @@ const Breadcrumb = ({ document, onlyText }: Props) => {
</CollectionName>
{isNestedDocument && (
<>
<Slash /> <BreadcrumbMenu label={<Overflow />} path={menuPath} />
<Slash /> <BreadcrumbMenu path={menuPath} />
</>
)}
{lastPath && (
Expand All @@ -148,6 +144,11 @@ const Breadcrumb = ({ document, onlyText }: Props) => {
);
};

export const Slash = styled(GoToIcon)`
flex-shrink: 0;
fill: ${(props) => props.theme.divider};
`;

const Wrapper = styled(Flex)`
display: none;

Expand All @@ -168,22 +169,6 @@ const SmallSlash = styled(GoToIcon)`
opacity: 0.25;
`;

export const Slash = styled(GoToIcon)`
flex-shrink: 0;
fill: ${(props) => props.theme.divider};
`;

const Overflow = styled(MoreIcon)`
flex-shrink: 0;
transition: opacity 100ms ease-in-out;
fill: ${(props) => props.theme.divider};

&:active,
&:hover {
fill: ${(props) => props.theme.text};
}
`;

const Crumb = styled(Link)`
color: ${(props) => props.theme.text};
font-size: 15px;
Expand All @@ -199,12 +184,17 @@ const Crumb = styled(Link)`

const CollectionName = styled(Link)`
display: flex;
flex-shrink: 0;
flex-shrink: 1;
color: ${(props) => props.theme.text};
font-size: 15px;
font-weight: 500;
white-space: nowrap;
overflow: hidden;
min-width: 0;

svg {
flex-shrink: 0;
}
`;

export default observer(Breadcrumb);
22 changes: 0 additions & 22 deletions app/components/BreadcrumbMenu.js

This file was deleted.

29 changes: 20 additions & 9 deletions app/components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ const RealButton = styled.button`
cursor: pointer;
user-select: none;

svg {
fill: ${(props) => props.iconColor || props.theme.buttonText};
}
${(props) =>
!props.borderOnHover &&
`
svg {
fill: ${props.iconColor || props.theme.buttonText};
}
`}

&::-moz-focus-inner {
padding: 0;
Expand All @@ -42,7 +46,7 @@ const RealButton = styled.button`
}

${(props) =>
props.neutral &&
props.$neutral &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does the leading $ mean generally?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stops it being added to the dom by styled-components: https://styled-components.com/docs/api#transient-props

`
background: ${props.theme.buttonNeutralBackground};
color: ${props.theme.buttonNeutralText};
Expand All @@ -52,9 +56,14 @@ const RealButton = styled.button`
: `rgba(0, 0, 0, 0.07) 0px 1px 2px, ${props.theme.buttonNeutralBorder} 0 0 0 1px inset`
};

svg {
${
props.borderOnHover
? ""
: `svg {
fill: ${props.iconColor || props.theme.buttonNeutralText};
}`
}


&:hover {
background: ${darken(0.05, props.theme.buttonNeutralBackground)};
Expand All @@ -72,9 +81,9 @@ const RealButton = styled.button`
background: ${props.theme.danger};
color: ${props.theme.white};

&:hover {
background: ${darken(0.05, props.theme.danger)};
}
&:hover {
background: ${darken(0.05, props.theme.danger)};
}
`};
`;

Expand Down Expand Up @@ -108,6 +117,7 @@ export type Props = {
children?: React.Node,
innerRef?: React.ElementRef<any>,
disclosure?: boolean,
neutral?: boolean,
fullwidth?: boolean,
borderOnHover?: boolean,
};
Expand All @@ -119,13 +129,14 @@ function Button({
value,
disclosure,
innerRef,
neutral,
...rest
}: Props) {
const hasText = children !== undefined || value !== undefined;
const hasIcon = icon !== undefined;

return (
<RealButton type={type} ref={innerRef} {...rest}>
<RealButton type={type} ref={innerRef} $neutral={neutral} {...rest}>
<Inner hasIcon={hasIcon} hasText={hasText} disclosure={disclosure}>
{hasIcon && icon}
{hasText && <Label hasIcon={hasIcon}>{children || value}</Label>}
Expand Down
13 changes: 13 additions & 0 deletions app/components/ContextMenu/Header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @flow
import styled from "styled-components";

const Header = styled.h3`
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
color: ${(props) => props.theme.sidebarText};
letter-spacing: 0.04em;
margin: 1em 12px 0.5em;
`;

export default Header;
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
// @flow
import { CheckmarkIcon } from "outline-icons";
import * as React from "react";
import { MenuItem as BaseMenuItem } from "reakit/Menu";
import styled from "styled-components";

type Props = {
onClick?: (SyntheticEvent<>) => void | Promise<void>,
children?: React.Node,
selected?: boolean,
disabled?: boolean,
as?: string | React.ComponentType<*>,
};

const DropdownMenuItem = ({
const MenuItem = ({
onClick,
children,
selected,
disabled,
as,
...rest
}: Props) => {
return (
<MenuItem
<BaseMenuItem
onClick={disabled ? undefined : onClick}
disabled={disabled}
role="menuitem"
tabIndex="-1"
{...rest}
>
{selected !== undefined && (
<>
{selected ? <CheckmarkIcon /> : <Spacer />}
&nbsp;
</>
{(props) => (
<MenuAnchor as={onClick ? "button" : as} {...props}>
{selected !== undefined && (
<>
{selected ? <CheckmarkIcon /> : <Spacer />}
&nbsp;
</>
)}
{children}
</MenuAnchor>
)}
{children}
</MenuItem>
</BaseMenuItem>
);
};

Expand All @@ -41,13 +46,14 @@ const Spacer = styled.div`
height: 24px;
`;

const MenuItem = styled.a`
export const MenuAnchor = styled.a`
display: flex;
margin: 0;
border: 0;
padding: 6px 12px;
width: 100%;
min-height: 32px;

background: none;
color: ${(props) =>
props.disabled ? props.theme.textTertiary : props.theme.textSecondary};
justify-content: left;
Expand All @@ -61,6 +67,7 @@ const MenuItem = styled.a`
}

svg {
flex-shrink: 0;
opacity: ${(props) => (props.disabled ? ".5" : 1)};
}

Expand All @@ -69,7 +76,8 @@ const MenuItem = styled.a`
? "pointer-events: none;"
: `

&:hover {
&:hover,
&.focus-visible {
color: ${props.theme.white};
background: ${props.theme.primary};
box-shadow: none;
Expand All @@ -87,4 +95,4 @@ const MenuItem = styled.a`
`};
`;

export default DropdownMenuItem;
export default MenuItem;
21 changes: 21 additions & 0 deletions app/components/ContextMenu/OverflowMenuButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @flow
import { MoreIcon } from "outline-icons";
import * as React from "react";
import { MenuButton } from "reakit/Menu";
import NudeButton from "components/NudeButton";

export default function OverflowMenuButton({
iconColor,
className,
...rest
}: any) {
return (
<MenuButton {...rest}>
{(props) => (
<NudeButton className={className} {...props}>
<MoreIcon color={iconColor} />
</NudeButton>
)}
</MenuButton>
);
}
16 changes: 16 additions & 0 deletions app/components/ContextMenu/Separator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @flow
import * as React from "react";
import { MenuSeparator } from "reakit/Menu";
import styled from "styled-components";

export default function Separator(rest: {}) {
return (
<MenuSeparator {...rest}>
{(props) => <HorizontalRule {...props} />}
</MenuSeparator>
);
}

const HorizontalRule = styled.hr`
margin: 0.5em 12px;
`;