Skip to content

Commit

Permalink
refactor(menu): use react.context and simplify logic (#13146)
Browse files Browse the repository at this point in the history
* refactor(menu): use react.context and simplify logic

* test(menu): fix test

* fix(menu): fix typo

* fix(menu): fix MenuItemSelectable function name

* fix(menu): combine adhacent conditional rendering blocks

* refactor(menu): add dummy 'dispatch' to menuDefaultState

* fix(menu): clear list of registered items when menu is closed

* fix(menu): prevent calling 'handleClose' twice

* fix(menu): fix focus return

* docs(menu): fix ContextMenu story actions

* fix(menu): close overflowmenuv2 on blur

---------

Co-authored-by: Francine Lucca <[email protected]>
  • Loading branch information
janhassel and francinelucca authored Feb 21, 2023
1 parent 1cf8fa7 commit a5d3821
Show file tree
Hide file tree
Showing 22 changed files with 1,002 additions and 1,504 deletions.
180 changes: 76 additions & 104 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9059,94 +9059,17 @@ Map {
},
},
"unstable_Menu" => Object {
"MenuDivider": Object {},
"MenuGroup": Object {
"propTypes": Object {
"children": Object {
"type": "node",
},
"label": Object {
"isRequired": true,
"type": "node",
},
},
},
"MenuItem": Object {
"propTypes": Object {
"children": Object {
"type": "node",
},
"disabled": Object {
"type": "bool",
},
"kind": Object {
"args": Array [
Array [
"default",
"danger",
],
],
"type": "oneOf",
},
"label": Object {
"isRequired": true,
"type": "node",
},
"shortcut": Object {
"type": "node",
},
},
},
"MenuRadioGroup": 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",
},
},
},
"MenuSelectableItem": Object {
"propTypes": Object {
"initialChecked": Object {
"type": "bool",
},
"label": Object {
"isRequired": true,
"type": "node",
},
"onChange": Object {
"type": "func",
},
},
},
"$$typeof": Symbol(react.forward_ref),
"propTypes": Object {
"children": Object {
"type": "node",
},
"className": Object {
"type": "string",
},
"id": Object {
"label": Object {
"type": "string",
},
"level": Object {
"type": "number",
},
"onClose": Object {
"type": "func",
},
Expand All @@ -9156,6 +9079,7 @@ Map {
"size": Object {
"args": Array [
Array [
"xs",
"sm",
"md",
"lg",
Expand Down Expand Up @@ -9203,24 +9127,17 @@ Map {
"type": "oneOfType",
},
},
},
"unstable_MenuDivider" => Object {},
"unstable_MenuGroup" => Object {
"propTypes": Object {
"children": Object {
"type": "node",
},
"label": Object {
"isRequired": true,
"type": "node",
},
},
"render": [Function],
},
"unstable_MenuItem" => Object {
"$$typeof": Symbol(react.forward_ref),
"propTypes": Object {
"children": Object {
"type": "node",
},
"className": Object {
"type": "string",
},
"disabled": Object {
"type": "bool",
},
Expand All @@ -9235,26 +9152,69 @@ Map {
},
"label": Object {
"isRequired": true,
"type": "node",
"type": "string",
},
"onClick": Object {
"type": "func",
},
"renderIcon": Object {
"args": Array [
Array [
Object {
"type": "func",
},
Object {
"type": "object",
},
],
],
"type": "oneOfType",
},
"shortcut": Object {
"type": "string",
},
},
"render": [Function],
},
"unstable_MenuItemDivider" => Object {
"$$typeof": Symbol(react.forward_ref),
"propTypes": Object {
"className": Object {
"type": "string",
},
},
"render": [Function],
},
"unstable_MenuItemGroup" => Object {
"$$typeof": Symbol(react.forward_ref),
"propTypes": Object {
"children": Object {
"type": "node",
},
"className": Object {
"type": "string",
},
"label": Object {
"isRequired": true,
"type": "string",
},
},
"render": [Function],
},
"unstable_MenuRadioGroup" => Object {
"unstable_MenuItemRadioGroup" => Object {
"$$typeof": Symbol(react.forward_ref),
"propTypes": Object {
"initialSelectedItem": Object {
"className": Object {
"type": "string",
},
"defaultSelectedItem": Object {
"type": "any",
},
"itemToString": Object {
"type": "func",
},
"items": Object {
"args": Array [
Object {
"type": "string",
},
],
"isRequired": true,
"type": "arrayOf",
"type": "array",
},
"label": Object {
"isRequired": true,
Expand All @@ -9263,21 +9223,33 @@ Map {
"onChange": Object {
"type": "func",
},
"selectedItem": Object {
"type": "any",
},
},
"render": [Function],
},
"unstable_MenuSelectableItem" => Object {
"unstable_MenuItemSelectable" => Object {
"$$typeof": Symbol(react.forward_ref),
"propTypes": Object {
"initialChecked": Object {
"className": Object {
"type": "string",
},
"defaultSelected": Object {
"type": "bool",
},
"label": Object {
"isRequired": true,
"type": "node",
"type": "string",
},
"onChange": Object {
"type": "func",
},
"selected": Object {
"type": "bool",
},
},
"render": [Function],
},
"unstable_OverflowMenuV2" => Object {
"propTypes": Object {
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ describe('Carbon Components React', () => {
"unstable_FeatureFlags",
"unstable_LayoutDirection",
"unstable_Menu",
"unstable_MenuDivider",
"unstable_MenuGroup",
"unstable_MenuItem",
"unstable_MenuRadioGroup",
"unstable_MenuSelectableItem",
"unstable_MenuItemDivider",
"unstable_MenuItemGroup",
"unstable_MenuItemRadioGroup",
"unstable_MenuItemSelectable",
"unstable_OverflowMenuV2",
"unstable_PageSelector",
"unstable_Pagination",
Expand Down
Loading

0 comments on commit a5d3821

Please sign in to comment.