Skip to content

Respect per-task readonly in keyboard navigation shortcuts - #157

Open
stepan-kuntso wants to merge 1 commit into
DHTMLX:masterfrom
stepan-kuntso:fix/keyboard-nav-task-readonly
Open

stepan-kuntso wants to merge 1 commit into
DHTMLX:masterfrom
stepan-kuntso:fix/keyboard-nav-task-readonly

Conversation

@stepan-kuntso

Copy link
Copy Markdown

What is broken

With the keyboard_navigation plugin, a task that has readonly: true (or config.readonly_property) can still be changed from the keyboard, although the mouse respects the flag:

Key on the focused row of a read-only task Before Mouse equivalent
Enter opens the lightbox; Save writes the changes double click: nothing
Ctrl+Enter creates a subtask under the read-only task
Shift+Right / Shift+Left indents / outdents the read-only task
Delete nothing (already blocked further down, in gantt.$click.buttons.delete)

How to reproduce

gantt.plugins({ keyboard_navigation: true });
gantt.config.date_format = "%Y-%m-%d";
gantt.init("gantt_here");
gantt.parse({
	data: [
		{ id: 1, text: "Project", start_date: "2026-06-01", duration: 6, open: true },
		{ id: 2, text: "Editable task", start_date: "2026-06-01", duration: 3, parent: 1 },
		{ id: 3, text: "Read-only task", start_date: "2026-06-02", duration: 2, parent: 1, readonly: true },
		{ id: 4, text: "Another task", start_date: "2026-06-04", duration: 2, parent: 1 }
	],
	links: []
});

Reload the page before each step, so every step starts from the same tree.

  1. Tab into the grid and move to "Read-only task" with the arrow keys (or click its row).
  2. Press Enter: the lightbox opens. Change the description, press Save: the task is renamed.
  3. Press Ctrl+Enter (the Control key on macOS as well): a "New task" is added under "Read-only task" and its lightbox opens.
  4. Press Shift+Right: "Read-only task" becomes a subtask of "Editable task".
  5. Press Shift+Left: "Read-only task" moves out of "Project" to the top level.
  6. Double click "Read-only task": the lightbox does not open (expected).

Checked on master (10.0.3) in Chrome on macOS.

Cause

src/ext/keyboard_navigation/elements/task_row.js, the handlers for shift+right, shift+left, delete, enter and ctrl+enter, call gantt.isReadonly(this). this is the keyboard navigation node (TaskRow or TaskCell, which reuses these keys), not the task. gantt.isReadonly(item) reads item[config.readonly_property] and item[config.editable_property], which the node does not have, so only config.readonly is checked.

Fix

Pass the task id: gantt.isReadonly(this.taskId). isReadonly accepts an id and looks the task up. Both TaskRow and TaskCell set this.taskId. Five identical one-line changes in one file.

Side effect, consistent with the mouse: with config.readonly = true, a task with editable: true (config.editable_property) can now be opened with Enter, as with a double click. Before, the keys refused it.

How to verify

I tested it manually in Chrome on macOS with the page above:

  • master: Enter on "Read-only task" opens the lightbox.
  • This branch: Enter, Ctrl+Enter, Shift+Right and Shift+Left on "Read-only task" do nothing. Enter on "Editable task" still opens the lightbox, and Delete on "Another task" still asks for confirmation.
  • This branch, with gantt.config.readonly = true: Enter is refused on "Another task" and accepted on a task with editable: true.

npm run build, npm run lint and npm run test (128 samples) pass.

The task row shortcuts passed the keyboard navigation node to
gantt.isReadonly() instead of the task, so only the chart-wide
config.readonly was checked. Enter opened the lightbox of a read-only
task and saved changes, Ctrl+Enter added a subtask to it and
Shift+Left/Right moved it.
@gearcoded

Copy link
Copy Markdown

@stepan-kuntso,
Thank you for reporting the issue. I added it as a bug to our internal bug tracker. The dev team will fix it in the future, but I cannot give you any ETA.

@stepan-kuntso

Copy link
Copy Markdown
Author

Thank you. The pull request already contains a fix (one file, the
isReadonly checks in task_row.js) and the steps I used to verify it, in
case that saves the team some time. Happy to adjust it if you prefer a
different approach.

@AlexKlimenkov

Copy link
Copy Markdown
Contributor

Hi @stepan-kuntso!

We've reviewed the change and accepted it. We also flagged a related gap - the '+' button in the grid row of a read-only task adds a subtask because it checks only the global readonly config. Since we accepted that the readonly task should get no new subtask, the same rule will apply to the "+" button - it will be hidden for read-only rows.

As before, we'll apply the change to the internal repo together with regression tests. It will ship in Gantt 10.1, I'll close this PR with a link to the release.

Thanks again for the contribution!

@stepan-kuntso

Copy link
Copy Markdown
Author

Thank you, and good catch on the "+" button, hiding it for read-only
rows makes sense. Glad it helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants