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

feat: add context-menu #7350

Merged
merged 60 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
c003bde
chore(ContextMenu): scaffold new component
janhassel Nov 27, 2020
21e01a1
feat(context-menu): build basic structure and styling
janhassel Nov 27, 2020
e435d19
feat(context-menu): build basic nesting support
janhassel Nov 27, 2020
37a38ce
feat(context-menu): use button markup
janhassel Nov 27, 2020
cc571c2
feat(context-menu): add support for disabled options
janhassel Nov 27, 2020
80e2a72
feat(context-menu): add support fort shortcuts
janhassel Nov 27, 2020
f94c6c4
feat(context-menu): add support for icons
janhassel Nov 27, 2020
3e3627c
feat(context-menu): add divider component
janhassel Nov 27, 2020
571a4cc
feat(context-menu): add support for selectable option
janhassel Nov 27, 2020
90c87ec
fix(context-menu): also indent options when sibling is selectable
janhassel Nov 27, 2020
b45b0ca
feat(context-menu): add support for radio groups
janhassel Nov 27, 2020
72a8b42
fix(context-menu): add support for initialSelectedItem in radio groups
janhassel Nov 27, 2020
127608d
fix(context-menu): also indent options when sibling is radio
janhassel Nov 30, 2020
f6db40e
feat(context-menu): add support for keyboard navigation
janhassel Nov 30, 2020
0f6c22d
feat(context-menu): dynamically reverse menu direction
janhassel Nov 30, 2020
fdb5d39
feat(context-menu): add props.onClose
janhassel Nov 30, 2020
8112a4a
chore(context-menu): add inline notification to story
janhassel Nov 30, 2020
05ff8ed
fix(context-menu): fix styling issues
janhassel Nov 30, 2020
d528a70
Merge branch 'master' into context-menu
janhassel Dec 8, 2020
2805167
refactor(context-menu): rename SelectableContextMenuOption to Context…
janhassel Dec 8, 2020
5fcae94
fix(context-menu): don't overwrite checkbox or radio role
janhassel Dec 8, 2020
620d1e4
fix(context-menu): automatically close menu after item was clicked
janhassel Dec 8, 2020
b129efe
fix(context-menu): improve behaviour with screenreaders
janhassel Dec 8, 2020
02b40cb
fix(context-menu): add onChange to radio group and checkbox
janhassel Dec 8, 2020
d2913d2
test(context-menu): update public-api and index snapshots
janhassel Dec 8, 2020
9b45e74
chore(context-menu): correct formatting
janhassel Dec 8, 2020
bb1e049
test(context-menu): add render tests
janhassel Dec 8, 2020
e5ad640
chore: run prettier
janhassel Dec 8, 2020
20837fe
fix(context-menu): focus entire menu on open
janhassel Dec 11, 2020
26babe8
fix(context-menu): only open submenu on long hover or right arrow
janhassel Dec 11, 2020
1d13ee0
feat(context-menu): always keep menu within body boundaries
janhassel Dec 14, 2020
8526682
fix(context-menu): implement review feedback
janhassel Jan 18, 2021
00aa073
fix(context-menu): don't close when disabled or divider was clicked
janhassel Jan 18, 2021
b1e8a2a
fix(context-menu): prevent menu from closing immediately in Safari
janhassel Jan 19, 2021
0cabaa9
refactor(context-menu): separate between external and internal component
janhassel Feb 5, 2021
ba3f46f
refactor(context-menu): mark as unstable
janhassel Feb 5, 2021
d402cf8
feat(context-menu): export useContextMenu hook
janhassel Feb 5, 2021
37734be
test(context-menu): replace Option component with Item component
janhassel Feb 5, 2021
3cf5727
Merge branch 'master' into context-menu
janhassel Feb 5, 2021
f3fc9d7
test: update react index snapshot
janhassel Feb 5, 2021
5d53550
fix(context-menu): open submenus on enter
janhassel Feb 10, 2021
92115b2
fix(context-menu): fix lint issue
janhassel Feb 10, 2021
21bcc8a
Merge branch 'master' into context-menu
andreancardona Feb 11, 2021
b8d7d0f
fix(context-menu): use menuitem* roles for checkbox and radio
janhassel Feb 12, 2021
cb1f945
fix(context-menu): remove aria-label from menuitems
janhassel Feb 12, 2021
8baccee
refactor(context-menu): remove button markup
janhassel Feb 12, 2021
46447ec
test(context-menu): update test to reflect markup changes
janhassel Feb 12, 2021
e6c44cf
fix(context-menu): use ul without role for radio groups
janhassel Feb 12, 2021
f3e6c4a
fix(context-menu): fix aria-haspopup attribute on parent node
janhassel Feb 23, 2021
13bd35a
fix(context-menu): add aria-expanded attribute on items with children
janhassel Feb 23, 2021
ae2b0fd
fix(context-menu): add "group" role to radio groups
janhassel Feb 23, 2021
a2272b4
fix(context-menu): extract radio items from group when top level
janhassel Feb 23, 2021
14198a3
chore: add story with multiple radio groups
janhassel Feb 23, 2021
ccd98ef
feat(context-menu): add ContextMenuGroup component
janhassel Feb 23, 2021
a548761
fix(context-menu): support "space" to activate items
janhassel Feb 23, 2021
b5c8253
Merge branch 'master' into context-menu
tw15egan Feb 24, 2021
e8da1a7
Merge branch 'main' into context-menu
janhassel Mar 9, 2021
db10c79
chore: add context menu story to experimental group
janhassel Mar 9, 2021
20b9838
fix(context-menu): prevents error where user must click twice to open
janhassel Mar 9, 2021
4ca8433
Merge branch 'main' into context-menu
kodiakhq[bot] Mar 10, 2021
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
128 changes: 128 additions & 0 deletions packages/components/src/components/context-menu/_context-menu.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//
// Copyright IBM Corp. 2020
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@import '../../globals/scss/vars';
@import '../../globals/scss/vendor/@carbon/elements/scss/import-once/import-once';
@import '../../globals/scss/helper-mixins';
@import '../../globals/scss/css--reset';

/// Context Menu styles
/// @access private
/// @group context-menu
@mixin context-menu {
.#{$prefix}--context-menu {
@include box-shadow;

position: fixed;
z-index: z('modal');
min-width: 13rem;
max-width: 18rem;
padding: $spacing-02 0;
background-color: $ui-01;
visibility: hidden;
}

.#{$prefix}--context-menu--open {
visibility: visible;

&:focus {
@include focus-outline('border');
}
}

.#{$prefix}--context-menu--invisible {
opacity: 0;
}

.#{$prefix}--context-menu-option {
position: relative;
height: $spacing-07;
background-color: $ui-01;
transition: background-color $duration--fast-01 motion(standard, productive);
}

.#{$prefix}--context-menu-option--active,
.#{$prefix}--context-menu-option:hover {
background-color: $hover-ui;
}

.#{$prefix}--context-menu-option > .#{$prefix}--context-menu {
margin-top: calc(#{$spacing-02} * -1);
}

.#{$prefix}--context-menu-option__content {
@include button-reset;

display: flex;
align-items: center;
justify-content: space-between;
height: 100%;
padding: 0 $spacing-05;

&:focus {
@include focus-outline('outline');
}
}

.#{$prefix}--context-menu-option__content--disabled {
background-color: $ui-01;
cursor: not-allowed;
}

.#{$prefix}--context-menu-option__content--disabled
.#{$prefix}--context-menu-option__label,
.#{$prefix}--context-menu-option__content--disabled
.#{$prefix}--context-menu-option__info,
.#{$prefix}--context-menu-option__content--disabled
.#{$prefix}--context-menu-option__icon {
color: $disabled-02;
}

.#{$prefix}--context-menu-option__content--indented
.#{$prefix}--context-menu-option__label {
margin-left: $spacing-05;
}

.#{$prefix}--context-menu-option__label {
@include type-style('body-short-01');

flex-grow: 1;
// add top/bottom padding to make sure letters are not cut off by hidden overflow
padding: $spacing-02 0;
overflow: hidden;
color: $text-01;
white-space: nowrap;
text-align: start;
text-overflow: ellipsis;
}

.#{$prefix}--context-menu-option__info {
display: inline-flex;
margin-left: $spacing-05;
color: $icon-01;
}

.#{$prefix}--context-menu-option__icon {
display: flex;
align-items: center;
width: 1rem;
height: 1rem;
margin-right: $spacing-03;
color: $icon-01;
}

.#{$prefix}--context-menu-divider {
width: 100%;
height: 1px;
margin: $spacing-02 0;
background-color: $ui-03;
}
}

@include exports('context-menu') {
@include context-menu;
}
1 change: 1 addition & 0 deletions packages/components/src/globals/scss/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ $deprecations--message: 'Deprecated code was found, this code will be removed be
@import '../../components/code-snippet/code-snippet';
@import '../../components/overflow-menu/overflow-menu';
@import '../../components/content-switcher/content-switcher';
@import '../../components/context-menu/context-menu';
@import '../../components/date-picker/date-picker';
@import '../../components/dropdown/dropdown';
@import '../../components/loading/loading';
Expand Down
1 change: 1 addition & 0 deletions packages/react/.storybook/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ $prefix: 'bx';
@import '~carbon-components/src/components/code-snippet/code-snippet';
@import '~carbon-components/src/components/overflow-menu/overflow-menu';
@import '~carbon-components/src/components/content-switcher/content-switcher';
@import '~carbon-components/src/components/context-menu/context-menu';
@import '~carbon-components/src/components/date-picker/date-picker';
@import '~carbon-components/src/components/dropdown/dropdown';
@import '~carbon-components/src/components/loading/loading';
Expand Down
139 changes: 139 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7563,5 +7563,144 @@ Map {
},
},
},
"unstable_ContextMenu" => Object {
"ContextMenuDivider": Object {},
"ContextMenuItem": Object {
"propTypes": Object {
"children": Object {
"type": "node",
},
"disabled": Object {
"type": "bool",
},
"label": Object {
"isRequired": true,
"type": "node",
},
"shortcut": Object {
"type": "node",
},
"shortcutText": Object {
"type": "string",
},
},
},
"ContextMenuRadioGroup": Object {
"propTypes": Object {
"initialSelectedItem": Object {
"type": "string",
},
"items": Object {
"args": Array [
Object {
"type": "string",
},
],
"isRequired": true,
"type": "arrayOf",
},
"label": Object {
"isRequired": true,
"type": "string",
},
"onChange": Object {
"type": "func",
},
},
},
"ContextMenuSelectableOption": Object {
"propTypes": Object {
"initialChecked": Object {
"type": "bool",
},
"label": Object {
"isRequired": true,
"type": "node",
},
"onChange": Object {
"type": "func",
},
},
},
"propTypes": Object {
"children": Object {
"type": "node",
},
"level": Object {
"type": "number",
},
"onClose": Object {
"type": "func",
},
"open": Object {
"type": "bool",
},
"x": Object {
"type": "number",
},
"y": Object {
"type": "number",
},
},
},
"unstable_ContextMenuItem" => Object {
"propTypes": Object {
"children": Object {
"type": "node",
},
"disabled": Object {
"type": "bool",
},
"label": Object {
"isRequired": true,
"type": "node",
},
"shortcut": Object {
"type": "node",
},
"shortcutText": Object {
"type": "string",
},
},
},
"unstable_ContextMenuDivider" => Object {},
"unstable_ContextMenuSelectableOption" => Object {
"propTypes": Object {
"initialChecked": Object {
"type": "bool",
},
"label": Object {
"isRequired": true,
"type": "node",
},
"onChange": Object {
"type": "func",
},
},
},
"unstable_ContextMenuRadioGroup" => Object {
"propTypes": Object {
"initialSelectedItem": Object {
"type": "string",
},
"items": Object {
"args": Array [
Object {
"type": "string",
},
],
"isRequired": true,
"type": "arrayOf",
},
"label": Object {
"isRequired": true,
"type": "string",
},
"onChange": Object {
"type": "func",
},
},
},
"unstable_useContextMenu" => Object {},
}
`;
6 changes: 6 additions & 0 deletions packages/react/src/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,16 @@ describe('Carbon Components React', () => {
"TooltipDefinition",
"TooltipIcon",
"UnorderedList",
"unstable_ContextMenu",
"unstable_ContextMenuDivider",
"unstable_ContextMenuItem",
"unstable_ContextMenuRadioGroup",
"unstable_ContextMenuSelectableOption",
"unstable_PageSelector",
"unstable_Pagination",
"unstable_TreeNode",
"unstable_TreeView",
"unstable_useContextMenu",
]
`);
});
Expand Down
Loading