diff --git a/README.md b/README.md index 1350f9b..8732a55 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ You may handle actions onTaskDelete={onTaskDelete} onProgressChange={onProgressChange} onDoubleClick={onDblClick} + onClick={onClick} /> ``` @@ -72,6 +73,7 @@ npm start | :----------------- | :---------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------- | | onSelect | (task: Task, isSelected: boolean) => void | Specifies the function to be executed on the taskbar select or unselect event. | | onDoubleClick | (task: Task) => void | Specifies the function to be executed on the taskbar onDoubleClick event. | +| onClick | (task: Task) => void | Specifies the function to be executed on the taskbar onClick event. | | onDelete\* | (task: Task) => void/boolean/Promise/Promise | Specifies the function to be executed on the taskbar on Delete button press event. | | onDateChange\* | (task: Task, children: Task[]) => void/boolean/Promise/Promise | Specifies the function to be executed when drag taskbar event on timeline has finished. | | onProgressChange\* | (task: Task, children: Task[]) => void/boolean/Promise/Promise | Specifies the function to be executed when drag taskbar progress event has finished. | diff --git a/example/src/App.tsx b/example/src/App.tsx index b1115f2..4faa22c 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -52,6 +52,10 @@ const App = () => { alert("On Double Click event Id:" + task.id); }; + const handleClick = (task: Task) => { + console.log("On Click event Id:" + task.id); + }; + const handleSelect = (task: Task, isSelected: boolean) => { console.log(task.name + " has " + (isSelected ? "selected" : "unselected")); }; @@ -76,6 +80,7 @@ const App = () => { onDelete={handleTaskDelete} onProgressChange={handleProgressChange} onDoubleClick={handleDblClick} + onClick={handleClick} onSelect={handleSelect} onExpanderClick={handleExpanderClick} listCellWidth={isChecked ? "155px" : ""} @@ -89,6 +94,7 @@ const App = () => { onDelete={handleTaskDelete} onProgressChange={handleProgressChange} onDoubleClick={handleDblClick} + onClick={handleClick} onSelect={handleSelect} onExpanderClick={handleExpanderClick} listCellWidth={isChecked ? "155px" : ""} diff --git a/src/components/gantt/gantt.tsx b/src/components/gantt/gantt.tsx index 9b5b78a..1d1a194 100644 --- a/src/components/gantt/gantt.tsx +++ b/src/components/gantt/gantt.tsx @@ -60,6 +60,7 @@ export const Gantt: React.FunctionComponent = ({ onDateChange, onProgressChange, onDoubleClick, + onClick, onDelete, onSelect, onExpanderClick, @@ -411,6 +412,7 @@ export const Gantt: React.FunctionComponent = ({ onDateChange, onProgressChange, onDoubleClick, + onClick, onDelete, }; diff --git a/src/components/gantt/task-gantt-content.tsx b/src/components/gantt/task-gantt-content.tsx index 7f0bbdf..f2d907c 100644 --- a/src/components/gantt/task-gantt-content.tsx +++ b/src/components/gantt/task-gantt-content.tsx @@ -53,6 +53,7 @@ export const TaskGanttContent: React.FC = ({ onDateChange, onProgressChange, onDoubleClick, + onClick, onDelete, }) => { const point = svg?.current?.createSVGPoint(); @@ -230,6 +231,8 @@ export const TaskGanttContent: React.FC = ({ } } else if (action === "dblclick") { !!onDoubleClick && onDoubleClick(task); + } else if (action === "click") { + !!onClick && onClick(task); } // Change task event start else if (action === "move") { diff --git a/src/components/task-item/task-item.tsx b/src/components/task-item/task-item.tsx index fc20311..cf06284 100644 --- a/src/components/task-item/task-item.tsx +++ b/src/components/task-item/task-item.tsx @@ -100,6 +100,9 @@ export const TaskItem: React.FC = props => { onDoubleClick={e => { onEventStart("dblclick", task, e); }} + onClick={e => { + onEventStart("click", task, e); + }} onFocus={() => { onEventStart("select", task); }} diff --git a/src/types/gantt-task-actions.ts b/src/types/gantt-task-actions.ts index 01c2102..01e1292 100644 --- a/src/types/gantt-task-actions.ts +++ b/src/types/gantt-task-actions.ts @@ -6,6 +6,7 @@ export type GanttContentMoveAction = | "mouseleave" | "delete" | "dblclick" + | "click" | "select" | "" | BarMoveAction; diff --git a/src/types/public-types.ts b/src/types/public-types.ts index af7da95..9b52a91 100644 --- a/src/types/public-types.ts +++ b/src/types/public-types.ts @@ -44,6 +44,10 @@ export interface EventOption { * Invokes on bar double click. */ onDoubleClick?: (task: Task) => void; + /** + * Invokes on bar click. + */ + onClick?: (task: Task) => void; /** * Invokes on end and start time change. Chart undoes operation if method return false or error. */