Review main Abandoned

83566[TASK] Make dashboard editable via keyboard

Willi Wehmeier CR 0 V 0 Hard +299 −21 updated 02/24/25, 14:20

Commit message

Widgets can be focussed, moved and deleted with keyboard controls now.

When a widget get's focus by navigating to a focussable element inside
by pressing the tab key, the widget actions will appear now, instead
of appearing only on hover.
Additionally, an aria-live area has been added to make the move
process accessible for screenreader users.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 13

Review log 3955

Show 2030 earlier messages
  1. Willi Wehmeier uploaded patch set 1 03/22/24, 07:50

  2. Willi Wehmeier marked it work in progress 03/22/24, 07:51

  3. core-ci voted on patch set 1 V -1 03/22/24, 07:57 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54831

  4. Willi Wehmeier rebased onto patch set 2 V -1 04/02/24, 06:26

  5. core-ci voted on patch set 2 V -1 04/02/24, 06:32 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55123

  6. Willi Wehmeier uploaded patch set 3 V -1 04/08/24, 06:39

  7. core-ci voted on patch set 3 V -1 04/08/24, 06:44 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55535

  8. Willi Wehmeier uploaded patch set 4 V -1 04/08/24, 07:22

  9. core-ci voted on patch set 4 V +1 04/08/24, 07:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55537

  10. Willi Wehmeier uploaded patch set 5 V +1 04/09/24, 05:21

  11. core-ci voted on patch set 5 V +1 04/09/24, 05:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55588

  12. Willi Wehmeier marked it ready for review 04/09/24, 05:35

  13. Ayke Halder commented on patch set 5 04/10/24, 16:34

    Great job here to make this work! I have some minor issues which might be fixable, please have a look.

    _grid.scss:72

    In Firefox it only correctly styles preceding elements when the asterisk is removed: `.dashboard-item:has(~ .js-dashboard-item-focused)` Also see: https://developer.mozilla.org/en-US/docs/Web/CSS/:has#css

    widget-keyboard-control.ts:93

    May we somehow re-focus the drag-button of the `selectedElement`. So after moving an element we keep the focus on this element. Or does focusing the drag-button stop screenreaders from reading out the text from `ariaLiveSelector`?
  14. Ayke Halder commented on patch set 5 04/10/24, 16:58

    Another point about using 'Escape' and 'Tab' while moving is active.

    widget-keyboard-control.ts:62

    Maybe add some more actions while an element is selected: * The 'Escape' button should stop the move action and restore the order as before. * Other keys should not work anymore - but especially 'Tab' should not move the focus around. Pseudo-code: ``` if (null !== this.selectedElement) { if (event.code === 'Escape' && !event.repeat) { this.restoreOrderAndDeselectSelectedElement(event); } if (event.code === 'Tab') { event.preventDefault(); event.currentTarget.focus(); } } ```
  15. Willi Wehmeier uploaded patch set 6 V +1 04/11/24, 13:47

  16. core-ci voted on patch set 6 V -1 04/11/24, 13:53 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55774

  17. Willi Wehmeier commented on patch set 6 04/11/24, 13:59

    _grid.scss:72 Reply

    Changed 😊

    widget-keyboard-control.ts:62 Reply

    I've added the possibility to cancel the move process with the escape key, thanks for the suggestion! 😊 Additionally key inputs are prevented now when there's a selected element and only esc, space and up/down arrow keys are allowed.

    widget-keyboard-control.ts:93 Reply

    I'm setting the focus manually now after repositioning of a widget and the screenreader output (voiceover on macos with chrome) is kinda random. Sometimes the live area content is read out with the success message, sometimes the screenreader describes the focused button. Currently I have no idea how to improve this, but otherwise I think it doesn't confuse the user and still improves the accessibility.
  18. Ayke Halder commented on patch set 6 04/11/24, 17:40

    We should also focus the handle if the operation is unsuccessfull. E.g. these two use cases should result in the same focus state: Case A: 1. Focus drag-button by keyboard 2. Press [Space] -> element is selected. 3. Press [Space] again -> element is de-selected. -> Focus is on drag-button. Case B: 1. Focus drag-button by keyboard 2. Press [Space] -> element is selected 3. Press [Escape] -> element is de-sected -> Focus is **not** on drag-button. Focus should be on drag-button again.

    widget-keyboard-control.ts:114

    Maybe just save the current drag-button here before we set `this.selectedElement = null`: ```js const handle = (this.selectedElement.querySelector(this.dragButtonSelector) as HTMLElement); ```

    widget-keyboard-control.ts:119

    After save focus the handle: ```js handle.focus(); ```

    widget-keyboard-control.ts:189

    Also focus the handle if not successfull. Maybe move focus action into function `deselectSelectedElement` as we still have `this.selectedElement` over there.
  19. Ayke Halder commented on patch set 6 04/11/24, 17:54

    Some code style improvements - please check if they make sense.

    widget-keyboard-control.ts:14

    CS - add: `import Grid from '@typo3/dashboard/grid';`

    widget-keyboard-control.ts:22

    CS - use Grid type: `private gridInstance: typeof Grid = null;`

    widget-keyboard-control.ts:37

    CS - use Grid type: `public initialize(muuriInstance: Muuri, grid: typeof Grid): void {`

    widget-keyboard-control.ts:98

    CS: I would use `event.currentTarget` instead of `event.target` as the event listener is bound to the drag-button anyway. See https://stackoverflow.com/a/10086501 > Events bubble by default. So the difference between the two is: > > * target is the element that triggered the event (e.g., the user clicked on) > * currentTarget is the element that the event listener is attached to.

    widget-keyboard-control.ts:186

    CS - ts-expect-error can be removed here.
  20. Willi Wehmeier uploaded patch set 7 V -1 04/12/24, 06:10

  21. core-ci voted on patch set 7 V -1 04/12/24, 06:15 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55832

  22. Willi Wehmeier commented on patch set 7 04/12/24, 06:33

    Reply

    The handle gets focused in both cases now (save/abort) 😎

    Reply

    All done! Thanks for your input!

    _grid.scss:72 Reply

    Done! But we'll still have to get the pipeline lint task fixed

    widget-keyboard-control.ts:14 Reply

    Done!

    widget-keyboard-control.ts:22 Reply

    Thanks for the 'typeof Grid' code example. That was the missing part 😄

    widget-keyboard-control.ts:37 Reply

    done!

    widget-keyboard-control.ts:98 Reply

    done 😊

    widget-keyboard-control.ts:114 Reply

    done!

    widget-keyboard-control.ts:119 Reply

    done!

    widget-keyboard-control.ts:186 Reply

    done!

    widget-keyboard-control.ts:189 Reply

    done!
  23. Andreas Kienast uploaded patch set 8 V -1 04/12/24, 09:29

  24. core-ci voted on patch set 8 V -1 04/12/24, 09:46 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55846

  25. core-ci voted on patch set 8 V +1 04/12/24, 09:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55846

  26. Andreas Kienast commented on patch set 8 CR -1 04/12/24, 10:07

    widget-keyboard-control.ts:59

    This and all other methods can be private, right?

    widget-keyboard-control.ts:74

    Why is this called so late?

    widget-keyboard-control.ts:198

    I'd prefer to export the class only and create the instance in grid.ts instead, this might make `initialize()` obsolete.

    locallang.xlf:15

    I know it's missing in the whole file, but could you please add the `resname` attributes?
  27. Ayke Halder commented on patch set 8 04/12/24, 10:07

    Looks pretty good now! Unfortunately I just realized what my suggestion to block the use of 'tab' and other keys while an element is selected really does. In Firefox the user cannot use internal browser functions at this moment anymore: * Zoom: [Ctrl] + [-] or [Ctrl] + [+] or [Ctrl] + [0] * Jump to url-bar: [Ctrl] + [L] Is this bad for UX or can we keep it like this?
  28. Willi Wehmeier rebased onto patch set 9 CR -1 V +1 04/12/24, 10:25

  29. Andreas Kienast commented on patch set 9 04/12/24, 10:29

    Reply

    IMO(!) browser shortcuts have precedence and should not get blocked.
  30. core-ci voted on patch set 9 V -1 04/12/24, 10:32 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55852

  1. Willi Wehmeier uploaded patch set 10 V -1 04/12/24, 10:43

  2. Willi Wehmeier commented on patch set 10 04/12/24, 10:47

    Reply

    I fixed that one with an early return when a key modifier is true in the KeyBoardEvent. It returns when the key that triggers the event is called together with ctrl/alt/option/cmd.

    widget-keyboard-control.ts:59 Reply

    changed the methods to be private.

    widget-keyboard-control.ts:74 Reply

    I've adjusted the placing to call the prevent as early as possible 😊

    widget-keyboard-control.ts:198 Reply

    done!

    locallang.xlf:15 Reply

    done!
  3. core-ci voted on patch set 10 V -1 04/12/24, 10:48 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55853

  4. Willi Wehmeier rebased onto patch set 11 V -1 04/12/24, 10:54

  5. core-ci voted on patch set 11 V +1 04/12/24, 10:59 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55857

  6. Willi Wehmeier uploaded patch set 12 V +1 04/12/24, 11:57

  7. core-ci voted on patch set 12 V +1 04/12/24, 12:04 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55863

  8. Ayke Halder commented on patch set 12 04/12/24, 12:39

    widget-keyboard-control.ts:62

    This might additionally need: `event.preventDefault();`
  9. Willi Wehmeier commented on patch set 12 04/12/24, 12:45

    widget-keyboard-control.ts:62 Reply

    The question is: what should be prevented when the condition states, that only space and enter will be evaluated?
  10. Ayke Halder commented on patch set 12 04/12/24, 12:49

    widget-keyboard-control.ts:59

    Maybe add an early return-condition here to have a clearly visible code-logic: ```js if (! this.selectedElement && ! (event.code === 'Space' || event.code === 'Enter')) { return; } event.preventDefault(); ``` Then we can remove the return-condition `if (! this.selectedElement)` and any `event.preventDefault()` in the code parts further down.
  11. Ayke Halder commented on patch set 12 04/12/24, 12:56

    widget-keyboard-control.ts:59 Reply

    Might get simplified to ```js if (! (this.selectedElement || event.code === 'Space' || event.code === 'Enter')) { return; } event.preventDefault(); ```
  12. Ayke Halder commented on patch set 12 04/12/24, 14:04

    widget-keyboard-control.ts:62 Reply

    In general I would go the approach: 1. Check that the input (`event.code`) should really be handled by this code. 2. Then for all handled inputs call `event.preventDefault()` and `event.stopPropagation()` - just in case. Note: `event.preventDefault()` also prevents browsers scrolling mechanism. ```js private handleKeyboardMoveEvent(event: KeyboardEvent): void { if (event.ctrlKey || event.altKey || event.metaKey) { return; } if (! event.code) { return; } if (! ['Space', 'Enter', 'Escape', 'ArrowDown', 'ArrowUp', 'Tab'].includes(event.code) ) { return; } if (! (this.selectedElement || ['Space', 'Enter'].includes(event.code))) { return; } event.preventDefault(); event.stopPropagation(); ``` Right now I found another edge case: The single keys PageUp/PageDown should still be working while an element is selected. Otherwise if there are too many elements you can't move the element to the right position by using ArrowDown/ArrowUp as you can't see the element anymore while moving it.
  13. Willi Wehmeier uploaded patch set 13 V +1 04/15/24, 08:22

  14. Willi Wehmeier commented on patch set 13 04/15/24, 08:25

    widget-keyboard-control.ts:62 Reply

    I've added PageUp, PageDown, Pos1/Hone and End to the keys, that are allowed to use while having an active widget to move. This should resolve your edge case 😊.
  15. core-ci voted on patch set 13 V +1 04/15/24, 08:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55983

  16. Ayke Halder commented on patch set 13 04/15/24, 13:16

    The refactoring to put the logics about keys into its own function `keyShouldBeHandled` is great! I would really appreciate to see not more keys than absolutely necessary blocked here. So better have a **white list** of all the keys that *really* are used by our code, than having the current **black list** of keys we like to pass to the browser. Such a black list must be extended every now and than. See the following single hotkey actions in Firefox: * F3: Find again / Opens search in page * F5: Reload * F6: Focus Address Bar / Move to Next Frame, Pop-Up * F7: Caret browsing * F11: Toggle Full Screen See https://support.mozilla.org/en-US/kb/keyboard-shortcuts-perform-firefox-tasks-quickly Other browser might have other important single key shortcuts. Accessbility tools like screenreaders or screen magnification might also add single key shortcuts. E.g. see https://www.freedomscientific.com/training/zoomtext/zoomtext-hotkeys/ > Layered Magnification Commands > > The following layered keys can be used to operate the Magnifier Commands. Press and release CAPS LOCK+SPACEBAR, followed by the keystrokes listed below to perform the action. > > | Command | Layered Keys | > | --- | --- | > | Magnifier Commands | CAPS LOCK+SPACEBAR, M | > | Enhance Colors On/Off | C | > | Enhance Cursor On/Off | R | > | Enhance Focus On/Off | F | > | Enhance Pointer On/Off | P | > | Enhance Smart Invert On/Off | I | > | Smoothing Mode | X | > | Toggle Zoom and 1x | ENTER | > | Zoom In | UP | > | Zoom Out | DOWN |

    widget-keyboard-control.ts:59 Reply

    Done

    widget-keyboard-control.ts:62 Reply

    I would really appreciate to see not more keys than absolutely necessary blocked here. Better have a **white list** of all the keys that *really* are used by our code, than having the current **black list** of keys we like to pass to the browser. Such a black list must be extended every now and than.
  17. Willi Wehmeier uploaded patch set 14 V +1 04/15/24, 14:18

  18. Willi Wehmeier commented on patch set 14 04/15/24, 14:19

    Reply

    Done!

    widget-keyboard-control.ts:62 Reply

    Done!
  19. core-ci voted on patch set 14 V +1 04/15/24, 14:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55995

  20. Ayke Halder commented on patch set 14 04/15/24, 14:27

    widget-keyboard-control.ts:62 Reply

    Done

    widget-keyboard-control.ts:83 Unresolved

    The old version had `ctrlKey`, `altKey` and `metaKey` handled, which is great. I would go for: ```js private static readonly ACTIVATION_KEYS string[] = ['Space', 'Enter']; private static readonly CONTROL_KEYS string[] = ['ArrowUp', 'ArrowDown', 'Space', 'Enter', 'Escape', 'Tab']; private keyShouldBeHandled(event: KeyboardEvent): boolean { if (!event.code || event.ctrlKey || event.altKey || event.metaKey) { return false; } if (WidgetKeyboardControl.ACTIVATION_KEYS.includes(event.code)) { return true; } if (!! this.selectedElement && WidgetKeyboardControl.CONTROL_KEYS.includes(event.code) ) { return true; } return false; } ```
  21. Benjamin Kott commented on patch set 14 CR -1 04/16/24, 11:29

    Unresolved

    on it
  22. Benjamin Kott commented on patch set 14 04/17/24, 13:31

    needs more work, postponed after 13.1
  23. Benni Mack updated the commit message in patch set 15 CR -1 V +1 10/18/24, 13:27

  24. core-ci voted on patch set 15 V -1 10/18/24, 21:15 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67967

  25. Benjamin Kott abandoned the change 02/24/25, 14:20