mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
"Show desktop drag handles" did nothing on a touch screen. The rule was isTouchScreenOrShowDesktopDragHandles() = isTouchScreen() || preference so on touch the OR was already true and the toggle could never hide the handles. Every place that decides whether to render a handle - minicard, list header, swimlane header - and every sortable handle selector goes through that one helper, so the setting was inert on exactly the devices that show handles. The setting is now THREE states, not two: on, off, and never-chosen. An explicit choice always wins (including OFF on a touch screen); only when the user has never chosen does the device decide, and then a touch screen still gets handles by default, because a finger needs something to grab. The rule lives in the pure models/lib/dragHandles.js so it can be unit-tested, and the toggle now stores a real `false` instead of removing the setting - that is what lets "turned off" be told apart from "never chosen". toggleDesktopDragHandles takes the explicit new state from the client (which alone knows whether this is a touch device) and still accepts no argument for older clients. Handles also decide what a DRAG MEANS, and that half was broken too: `.minicard` and `.list-header` carried `nodragscroll` unconditionally, so with handles ON a finger dragging across a card neither moved the card (only the handle does) nor panned the board (dragscroll was opted out) - it did nothing. They now opt out only when handles are OFF, i.e. only when the element IS the drag source. With handles on, the card body pans the board, which is the whole point of having handles. And the handle has to be reachable with a finger: it was a 20-28px icon in the bottom-right corner, a mouse-sized target that is close to unusable on a wall-mounted infoscreen. On a coarse pointer it becomes a 48px full-height strip down the leading edge (the Material minimum, and the easiest edge to thumb), with the card content padded to match. A mouse keeps the compact corner handle, since `pointer: coarse` does not match a mouse. Tab order: the keyboard card/list move buttons are focusable but `opacity: 0` and sit at the START of the card content, so tabbing went card (visible focus) -> invisible -> invisible -> next card and the focus ring kept vanishing and reappearing where it looked like it had gone backwards. They are now revealed while focused, the same pattern the skip-to-content link already uses. Adds tests/dragHandles.test.cjs: the three states, that an explicit OFF hides handles on touch (the reported bug), that an explicit choice always beats the device default, and that a corrupt stored value falls back to the device default rather than leaving a finger unable to drag. Thanks to xet7 !
40 lines
1.8 KiB
JavaScript
40 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
// Pure decision helper for "should drag handles be shown?" (#6521).
|
|
//
|
|
// Drag handles exist so that the REST of a card/list/swimlane is free for
|
|
// something else: with handles on, dragging the card body pans the board
|
|
// (dragscroll) and only the handle moves the card. So whether they are shown
|
|
// changes the meaning of every drag on the board, and the user must be able to
|
|
// decide it on any device.
|
|
//
|
|
// Three states, not two:
|
|
// * preference === true - the user turned handles ON
|
|
// * preference === false - the user turned handles OFF
|
|
// * preference === null - the user has never chosen; the device decides
|
|
//
|
|
// The old rule was `isTouchScreen() || preference`, which collapsed the three
|
|
// states into "always on for touch": on a touch screen the OR was already true,
|
|
// so the "Show desktop drag handles" toggle could not hide them there. Keeping
|
|
// "never chosen" distinct from "deliberately off" is the whole fix — the default
|
|
// for a touch screen stays ON (a finger needs something to grab), but an
|
|
// explicit OFF is now honoured everywhere.
|
|
|
|
function resolveShowDragHandles(preference, isTouchScreen) {
|
|
if (preference === true) return true;
|
|
if (preference === false) return false;
|
|
return !!isTouchScreen; // never chosen: touch gets handles, a mouse does not
|
|
}
|
|
|
|
// Normalize a stored value (user profile field or localStorage string) into the
|
|
// three states above. Anything unrecognized is "never chosen", so a corrupt or
|
|
// legacy value falls back to the device default rather than to an arbitrary
|
|
// boolean.
|
|
function readDragHandlesPreference(stored) {
|
|
if (stored === true || stored === 'true') return true;
|
|
if (stored === false || stored === 'false') return false;
|
|
return null;
|
|
}
|
|
|
|
module.exports = { resolveShowDragHandles, readDragHandlesPreference };
|