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(Menu): fix extra gap issue when the menu doesnt contain any item with icon #18718

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8026393
fix: rename package name
amal-k-joy Feb 18, 2025
4280f6a
feat(menu): cwc menu component
sangeethababu9223 Apr 24, 2024
8f84b06
feat(Menu): sub menu position ltr
sangeethababu9223 Apr 25, 2024
757731a
feat(menu): hover effects
sangeethababu9223 Apr 26, 2024
3d442ff
fix(menu): context for menu item
sangeethababu9223 Apr 29, 2024
81ca577
feat(menu): focus item via Keydown
sangeethababu9223 May 21, 2024
c3b7e95
feat(menu): navigate menu using keyboard
sangeethababu9223 May 24, 2024
bdc49c6
feat(menu): remove disabled menu item from navigation using keyboard
sangeethababu9223 May 24, 2024
7aa8d7f
feat(menu): refactoring
sangeethababu9223 May 27, 2024
c03abb7
feat(menu): virtualdom load check and update menu
sangeethababu9223 May 28, 2024
7b08f45
feat(Menu): label and icon update
sangeethababu9223 May 29, 2024
27804f5
feat(menu): submenu navigation keydown
sangeethababu9223 Jun 3, 2024
404c599
feat(menu): click navigation update
sangeethababu9223 Jun 3, 2024
f1e2e85
style update
sangeethababu9223 Jun 3, 2024
17aaf36
feat(menu): storybook doc for menu
sangeethababu9223 Jun 4, 2024
d4cc6a0
feat(menu): Storybook playground set up
sangeethababu9223 Jun 7, 2024
0eab875
feat(menu): style prefix update remove blur handling
sangeethababu9223 Jun 10, 2024
f10cb0a
feat(menu): ci check issue fix
sangeethababu9223 Jun 10, 2024
380b2bc
refactor(menu): update selectors wiith prefix variable and format the…
sangeethababu9223 Jun 10, 2024
840b68d
feat(menu): ci check fix
sangeethababu9223 Jun 10, 2024
c2f2a1c
feat(menu): add license text to menu.ts
sangeethababu9223 Jun 11, 2024
ac7e77e
fix: correct package name, folder structure and type errors
amal-k-joy Feb 19, 2025
ed4d188
fix: yarn cache for lit context
amal-k-joy Feb 24, 2025
5d2763c
Merge branch 'mergeMenuFromDotcom5' of github.com:amal-k-joy/carbon i…
amal-k-joy Feb 24, 2025
b46ba26
feat(menu): deprecate props.mode / always support full capabilities
amal-k-joy Feb 26, 2025
a5ba6ac
fix: storybook control change not reflecting
amal-k-joy Feb 26, 2025
fc06407
fix: extra spacing when there are no icons
amal-k-joy Feb 27, 2025
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
Binary file not shown.
3 changes: 0 additions & 3 deletions packages/icons-react/examples/storybook/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6970,9 +6970,7 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

<<<<<<< HEAD
"lodash@npm:^4.17.11, lodash@npm:^4.17.19":
=======
"lodash@npm:^4.17.11":
version: 4.17.11
resolution: "lodash@npm:4.17.11"
Expand All @@ -6981,7 +6979,6 @@ fsevents@^1.2.7:
linkType: hard

"lodash@npm:^4.17.19":
>>>>>>> main
version: 4.17.21
resolution: "lodash@npm:4.17.21"
checksum: eb835a2e51d381e561e508ce932ea50a8e5a68f4ebdd771ea240d3048244a8d13658acbd502cd4829768c56f2e16bdd4340b9ea141297d472517b83868e677f7
Expand Down
1 change: 1 addition & 0 deletions packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@carbon/styles": "^1.75.0",
"@floating-ui/dom": "^1.6.3",
"@ibm/telemetry-js": "^1.5.0",
"@lit/context": "^1.1.1",
"flatpickr": "4.6.13",
"lit": "^3.1.0",
"lodash-es": "^4.17.21",
Expand Down
15 changes: 15 additions & 0 deletions packages/web-components/src/components/menu/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @license
*
* Copyright IBM Corp. 2024
*
* 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 './menu';
import './menu-item';
import './menu-item-divider';
import './menu-item-group';
import './menu-item-selectable';
import './menu-item-radio-group';
29 changes: 29 additions & 0 deletions packages/web-components/src/components/menu/menu-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @license
*
* Copyright IBM Corp. 2024
*
* 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 { createContext } from '@lit/context';
export type StateType = {
isRoot: boolean;
hasSelectableItems: boolean;
size: 'xs' | 'sm' | 'md' | 'lg' | null;
items: any[];
requestCloseRoot: (e: KeyboardEvent) => void;
updateFromChild: (item: {}) => void;
};

export const menuDefaultState: StateType = {
isRoot: true,
hasSelectableItems: false,
size: null,
items: [],
requestCloseRoot: () => {},
updateFromChild: () => {},
};

export const MenuContext = createContext<StateType>('myData');
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @license
*
* Copyright IBM Corp. 2024
*
* 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 { LitElement, html } from 'lit';
import { prefix } from '../../globals/settings';
import styles from './menu-item.scss?lit';
import { carbonElement as customElement } from '../../globals/decorators/carbon-element';
/**
* Menu Item.
*
* @element cds-menu-item-divider
*/
@customElement(`${prefix}-menu-item-divider`)
class CDSmenuItemDivider extends LitElement {
render() {
return html`
<li class="${prefix}--menu-item-divider" role="separator"></li>
`;
}
static styles = styles; // `styles` here is a `CSSResult` generated by custom Vite loader
}
export default CDSmenuItemDivider;
40 changes: 40 additions & 0 deletions packages/web-components/src/components/menu/menu-item-group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @license
*
* Copyright IBM Corp. 2024
*
* 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 { LitElement, html } from 'lit';
import { property } from 'lit/decorators.js';
import { prefix } from '../../globals/settings';
import styles from './menu-item.scss?lit';
import { carbonElement as customElement } from '../../globals/decorators/carbon-element';
/**
* Menu Item.
*
* @element cds-menu-item-group
*/
@customElement(`${prefix}-menu-item-group`)
class CDSmenuItemGroup extends LitElement {
/**
* Label for the menu item.
*/
@property({ type: String })
label;

render() {
const { label } = this;
return html`
<li class="${prefix}--menu-item-group" role="none">
<ul role="group" aria-label="${label}">
<slot></slot>
</ul>
</li>
`;
}
static styles = styles; // `styles` here is a `CSSResult` generated by custom Vite loader
}
export default CDSmenuItemGroup;
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* @license
*
* Copyright IBM Corp. 2024
*
* 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 { LitElement, html } from 'lit';
import { property } from 'lit/decorators.js';
import { prefix } from '../../globals/settings';
import styles from './menu-item.scss?lit';
import { carbonElement as customElement } from '../../globals/decorators/carbon-element';
import { ChangeEventHandler } from 'react';
import { consume } from '@lit/context';
import { MenuContext } from './menu-context';

/**
* Menu Item.
*
* @element cds-menu-item-radio-group
*/
@customElement(`${prefix}-menu-item-radio-group`)
class CDSmenuItemRadioGroup extends LitElement {
@consume({ context: MenuContext })
context;

/**
* Label for the menu item radio group.
*/
@property({ type: String })
label;
/**
* List of items in the radio group.
*/
@property({ type: Array })
items = [];

/**
* Selected item in the radio group.
*/
@property({ type: String, attribute: true })
selectedItem;

/**
* List of items in the radio group.
*/
@property()
itemToString?: (item: Array<String | number>) => String;
/**
* Provide an optional function to be called when the selection state changes.
*/
@property()
onChange?: ChangeEventHandler;

firstUpdated(): void {
this.context.updateFromChild({ hasSelectableItems: true });
}

_handleClick = (item, e) => {
this.selectedItem = item;
if (this.onChange) {
this.onChange(e);
}
};
render() {
const defaultItemToString = (item) => item.toString();
const {
label,
items,
itemToString = defaultItemToString,
selectedItem,
_handleClick: handleClick,
} = this;
return html`
<li class="${prefix}--menu-item-radio-group" role="none">
<ul role="group" aria-label="${label}">
${items.map(
(item) => html`
<cds-menu-item
label="${itemToString(item)}"
role="menuitemradio"
aria-checked="${item === selectedItem}"
.onClick="${(e) => {
handleClick(item, e);
}}"></cds-menu-item>
`
)}
</ul>
</li>
`;
}
static styles = styles; // `styles` here is a `CSSResult` generated by custom Vite loader
}
export default CDSmenuItemRadioGroup;
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* @license
*
* Copyright IBM Corp. 2019, 2023
*
* 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 { LitElement, html } from 'lit';
import { property } from 'lit/decorators.js';
import { prefix } from '../../globals/settings';
import styles from './menu-item.scss?lit';
import { carbonElement as customElement } from '../../globals/decorators/carbon-element';
import { consume } from '@lit/context';
import { MenuContext } from './menu-context';
/**
* Menu Item.
*
* @element cds-menu-item
*/
@customElement(`${prefix}-menu-item-selectable`)
class CDSmenuItemSelectable extends LitElement {
@consume({ context: MenuContext })
context;
/**
* Label for the menu item selectable.
*/
@property({ type: String })
label;
/**
* Whether the menu item is selected or not.
*/
@property({ type: Boolean })
selected = false;

/**
* Provide an optional function to be called when the selection state changes.
*/
onChange?;

/**
* Sets the menu item's icon.
*/
@property()
renderIcon?: () => void;

@property()
shortcut;

_handleClick = (e) => {
this.selected = !this.selected;
if (this.onChange) {
this.onChange(e);
}
};

firstUpdated(): void {
this.context.updateFromChild({ hasSelectableItems: true });
}
render() {
const { label, selected, _handleClick: handleClick } = this;

return html`
<cds-menu-item
label="${label}"
class="${prefix}--menu-item-selectable--selected"
role="menuitemcheckbox"
shortcut=${this.shortcut}
aria-checked="${selected}"
.renderIcon=${this.renderIcon || undefined}
.onClick="${handleClick}"></cds-menu-item>
`;
}
static styles = styles; // `styles` here is a `CSSResult` generated by custom Vite loader
}
export default CDSmenuItemSelectable;
Loading
Loading