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

Content Tree: Event trigger on shift arrow keys #2509

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b009fa7
1713 - content tree event trigger on shift arrow keys
prashanthr6383 May 8, 2024
d2e8022
Merge branch 'main' into 1713---Content-Tree---Event-handling-for-Ctr…
prashanthr6383 May 8, 2024
52bcc37
1713 - content tree event trigger for select and deselect
prashanthr6383 May 20, 2024
af4c5f6
Merge branch 'main' into 1713---Content-Tree---Event-handling-for-Ctr…
prashanthr6383 May 27, 2024
6c9c774
Merge branch 'main' into 1713---Content-Tree---Event-handling-for-Ctr…
prashanthr6383 Jun 30, 2024
bd03c9a
1713 content tree event trigger on shift arrow keys
prashanthr6383 Jun 30, 2024
7511427
1713 naming convention fixes
prashanthr6383 Jun 30, 2024
b988569
Merge branch 'main' into 1713---Content-Tree---Event-handling-for-Ctr…
prashanthr6383 Jul 18, 2024
a0db365
1713 - content tree itemchange event to emit keyboard events
prashanthr6383 Jul 18, 2024
74770f9
1713 - code fixes and storybook update for itemChange
prashanthr6383 Jul 19, 2024
417024a
Merge branch 'main' into 1713---Content-Tree---Event-handling-for-Ctr…
prashanthr6383 Jul 19, 2024
2696729
Merge branch 'main' into 1713---Content-Tree---Event-handling-for-Ctr…
prashanthr6383 Aug 22, 2024
bb1dcc0
1713 - adding itemchange event for item click and story book update
prashanthr6383 Aug 22, 2024
cd94317
1713 - naming convention fix
prashanthr6383 Aug 22, 2024
e1a186f
Merge branch 'main' into 1713---Content-Tree---Event-handling-for-Ctr…
prashanthr6383 Aug 23, 2024
cb97053
1713 - naming convention fixes
prashanthr6383 Aug 23, 2024
843dbb0
1713 - storybook duplicate event fix
prashanthr6383 Aug 23, 2024
e5f3ddf
Update interfaces.d.ts
prashanth-offcl Aug 23, 2024
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
8 changes: 6 additions & 2 deletions stencil-workspace/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { TableCellEdited, TableContext } from "./components/modus-table/models/t
import { Tab } from "./components/modus-tabs/modus-tabs";
import { ModusTimePickerEventDetails } from "./components/modus-time-picker/modus-time-picker.models";
import { ModusToolTipPlacement } from "./components/modus-tooltip/modus-tooltip.models";
import { TreeViewItemInfo, TreeViewItemOptions } from "./components/modus-content-tree/modus-content-tree.types";
import { TreeItemSelectionChange, TreeViewItemInfo, TreeViewItemOptions } from "./components/modus-content-tree/modus-content-tree.types";
import { ModusActionBarOptions as ModusActionBarOptions1 } from "./components/modus-action-bar/modus-action-bar";
export { ModusActionBarOptions } from "./components/modus-action-bar/modus-action-bar";
export { ModusAutocompleteOption } from "./components/modus-autocomplete/modus-autocomplete";
Expand All @@ -49,7 +49,7 @@ export { TableCellEdited, TableContext } from "./components/modus-table/models/t
export { Tab } from "./components/modus-tabs/modus-tabs";
export { ModusTimePickerEventDetails } from "./components/modus-time-picker/modus-time-picker.models";
export { ModusToolTipPlacement } from "./components/modus-tooltip/modus-tooltip.models";
export { TreeViewItemInfo, TreeViewItemOptions } from "./components/modus-content-tree/modus-content-tree.types";
export { TreeItemSelectionChange, TreeViewItemInfo, TreeViewItemOptions } from "./components/modus-content-tree/modus-content-tree.types";
export { ModusActionBarOptions as ModusActionBarOptions1 } from "./components/modus-action-bar/modus-action-bar";
export namespace Components {
interface ModusAccordion {
Expand Down Expand Up @@ -2776,6 +2776,7 @@ declare global {
};
interface HTMLModusTreeViewElementEventMap {
"itemDrop": { [key: string]: TreeViewItemInfo };
"itemSelectionChange": TreeItemSelectionChange;
"itemActionClick": any;
}
interface HTMLModusTreeViewElement extends Components.ModusTreeView, HTMLStencilElement {
Expand All @@ -2796,6 +2797,7 @@ declare global {
"checkboxClick": boolean;
"itemLabelChange": string;
"itemClick": boolean;
"itemSelectionChange": TreeItemSelectionChange;
"itemExpandToggle": boolean;
"itemAdded": HTMLElement;
"actionClick": any;
Expand Down Expand Up @@ -4818,6 +4820,7 @@ declare namespace LocalJSX {
*/
"onItemActionClick"?: (event: ModusTreeViewCustomEvent<any>) => void;
"onItemDrop"?: (event: ModusTreeViewCustomEvent<{ [key: string]: TreeViewItemInfo }>) => void;
"onItemSelectionChange"?: (event: ModusTreeViewCustomEvent<TreeItemSelectionChange>) => void;
/**
* (optional) Set selected tree items
*/
Expand Down Expand Up @@ -4881,6 +4884,7 @@ declare namespace LocalJSX {
* An event that fires on tree item label changes
*/
"onItemLabelChange"?: (event: ModusTreeViewItemCustomEvent<string>) => void;
"onItemSelectionChange"?: (event: ModusTreeViewItemCustomEvent<TreeItemSelectionChange>) => void;
/**
* (optional) Tab Index for the tree item
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export type TreeViewItemInfo = {
level?: number;
};

export type TreeItemSelectionChange = {
nodeId: string;
isSelected: boolean;
};

export type TreeViewItemDragState = {
itemId: string;
dragContent: HTMLElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
FunctionalComponent,
} from '@stencil/core';
import { ModusIconMap } from '../../../icons/ModusIconMap';
import { TreeViewItemOptions } from '../modus-content-tree.types';
import { TreeItemSelectionChange, TreeViewItemOptions } from '../modus-content-tree.types';
import { TREE_ITEM_SIZE_CLASS } from '../modus-content-tree.constants';
import { ModusActionBarOptions } from '../../modus-action-bar/modus-action-bar';

Expand Down Expand Up @@ -53,6 +53,8 @@ export class ModusTreeViewItem {
/** An event that fires on tree item click */
@Event() itemClick: EventEmitter<boolean>;

@Event() itemSelectionChange: EventEmitter<TreeItemSelectionChange>;

/** An event that fires on tree item expand/collapse */
@Event() itemExpandToggle: EventEmitter<boolean>;

Expand Down Expand Up @@ -252,6 +254,9 @@ export class ModusTreeViewItem {

onItemSelection(this.nodeId, e);
this.itemClick.emit(hasItemSelected(this.nodeId));
if (!e.ctrlKey) {
this.itemSelectionChange.emit({ isSelected: hasItemSelected(this.nodeId), nodeId: this.nodeId });
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@

## Events

| Event | Description | Type |
| ------------------ | ------------------------------------------------------------------------------------- | ---------------------- |
| `actionClick` | Fired when an action button within the tree item is clicked. Includes the `actionId`. | `CustomEvent<any>` |
| `checkboxClick` | An event that fires on tree item checkbox click | `CustomEvent<boolean>` |
| `itemClick` | An event that fires on tree item click | `CustomEvent<boolean>` |
| `itemExpandToggle` | An event that fires on tree item expand/collapse | `CustomEvent<boolean>` |
| `itemLabelChange` | An event that fires on tree item label changes | `CustomEvent<string>` |
| Event | Description | Type |
| --------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------- |
| `actionClick` | Fired when an action button within the tree item is clicked. Includes the `actionId`. | `CustomEvent<any>` |
| `checkboxClick` | An event that fires on tree item checkbox click | `CustomEvent<boolean>` |
| `itemClick` | An event that fires on tree item click | `CustomEvent<boolean>` |
| `itemExpandToggle` | An event that fires on tree item expand/collapse | `CustomEvent<boolean>` |
| `itemLabelChange` | An event that fires on tree item label changes | `CustomEvent<string>` |
| `itemSelectionChange` | | `CustomEvent<{ nodeId: string; isSelected: boolean; }>` |


## Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import {
State,
Watch,
} from '@stencil/core';
import { TreeViewItemOptions, TreeViewItemInfo, TreeViewItemDragState, Position } from '../modus-content-tree.types';
import {
TreeViewItemOptions,
TreeViewItemInfo,
TreeViewItemDragState,
TreeItemSelectionChange,
Position,
} from '../modus-content-tree.types';
import { ModusContentTreeDragItem } from '../modus-content-tree-drag-item';

@Component({
Expand Down Expand Up @@ -54,6 +60,8 @@ export class ModusTreeView {

@Event() itemDrop: EventEmitter<{ [key: string]: TreeViewItemInfo }>;

@Event() itemSelectionChange: EventEmitter<TreeItemSelectionChange>;

private currentItem: TreeViewItemInfo;

private focusItem: string;
Expand Down Expand Up @@ -595,6 +603,10 @@ export class ModusTreeView {
current.focusItem();
}

handleChangeTreeitem(isSelected: boolean, nodeId: string): void {
this.itemSelectionChange.emit({ isSelected, nodeId });
}

handleItemSelection(itemId: string, event?: KeyboardEvent | MouseEvent): void {
if (this.items[itemId].disabled) return;
const allowMultipleSelection = this.multiSelection && event && (event.shiftKey || event.ctrlKey || event.metaKey);
Expand All @@ -606,11 +618,13 @@ export class ModusTreeView {
if (isSelected) {
if (allowMultipleSelection) {
newItems.push(itemId);
this.handleChangeTreeitem(true, itemId);
} else {
newItems = [itemId];
}
} else {
newItems = newItems.filter((i) => i !== itemId);
if (allowMultipleSelection) this.handleChangeTreeitem(false, itemId);
}
this.selectedItems = [...newItems];
this.syncItems.push(...oldItems, ...newItems);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

## Events

| Event | Description | Type |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
| `itemActionClick` | Fired when an action is clicked within any tree item. Includes both the `actionId` and `nodeId` of the action and item, respectively. | `CustomEvent<any>` |
| `itemDrop` | | `CustomEvent<{ [key: string]: TreeViewItemInfo; }>` |
| Event | Description | Type |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
| `itemActionClick` | Fired when an action is clicked within any tree item. Includes both the `actionId` and `nodeId` of the action and item, respectively. | `CustomEvent<any>` |
| `itemDrop` | | `CustomEvent<{ [key: string]: TreeViewItemInfo; }>` |
| `itemSelectionChange` | | `CustomEvent<{ nodeId: string; isSelected: boolean; }>` |


----------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion stencil-workspace/src/interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { Components, JSX } from './components';
export { Crumb } from './components/modus-breadcrumb/modus-breadcrumb';
export { TreeViewItemInfo } from './components/modus-content-tree/modus-content-tree.types';
export { TreeItemSelectionChange, TreeViewItemInfo } from './components/modus-content-tree/modus-content-tree.types';
export { ModusNavbarApp } from './components/modus-navbar/apps-menu/modus-navbar-apps-menu';
export * from './components/modus-data-table/modus-data-table.models';
export { ModusAutocompleteOption } from './components/modus-autocomplete/modus-autocomplete';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,11 @@ Every item and the elements such as drag icon, expand & collapse icon and the ch

#### Modus Tree View

| Name | Description | Emits |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------- |
| itemActionClick | Fired when an action is clicked within any tree item. Includes both the `actionId` and `nodeId` of the action and item, respectively. | `{ actionId: string, nodeId: string }` |
| itemDrop | Fired when an item is dropped in a different position. Includes the updated item's map. | `{ [key: string]: TreeViewItemInfo }` |
| Name | Description | Emits |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| itemActionClick | Fired when an action is clicked within any tree item. Includes both the `actionId` and `nodeId` of the action and item, respectively. | `{ actionId: string, nodeId: string }` |
| itemDrop | Fired when an item is dropped in a different position. Includes the updated item's map. | `{ [key: string]: TreeViewItemInfo }` |
| itemSelectionChange | Fired when the item's selection state changes by any means, such as mouse or keyboard interactions | `CustomEvent<{isSelected: boolean, nodeId: number}>` |

##### Modus Tree View Item

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default {
'itemClick modus-tree-view-item',
'itemLabelChange modus-tree-view-item',
'itemDrop modus-tree-view',
'itemSelectionChange modus-tree-view',
],
},
controls: { expanded: true, sort: 'requiredFirst' },
Expand Down