Skip to content

Slider widget keyBindings defined but never wired up #267

@KJ7LNW

Description

@KJ7LNW

Description

The Slider widget defines keyBindings for keyboard navigation (arrow keys, HOME, END, etc.) but they are never functional because:

  1. The onKey listener is never registered (this.on('key', this.onKey) is not called)
  2. No userActions handlers are defined for the action names in keyBindings

The source code even has a comment acknowledging this at line 93 of lib/document/Slider.js:

// Unused ATM: no onKey registered
Slider.prototype.keyBindings = {
    UP: 'backward',
    DOWN: 'forward',
    LEFT: 'backward',
    RIGHT: 'forward',
    PAGE_UP: 'backward',
    PAGE_DOWN: 'forward',
    ' ': 'forward',
    HOME: 'start',
    END: 'end'
};

Expected Behavior

Arrow keys, HOME, END, PAGE_UP, PAGE_DOWN, and SPACE should navigate the slider when it has focus, similar to how BaseMenu and other widgets handle keyboard input.

Actual Behavior

Keyboard navigation does not work. Only mouse interactions (click, drag, wheel) function correctly.

Suggested Fix

  1. Add userActions to Slider.prototype with handlers for backward/forward/start/end:
Slider.prototype.userActions = {
    backward: function() {
        this.emit('slideStep', -1);
        return true;
    },
    forward: function() {
        this.emit('slideStep', 1);
        return true;
    },
    start: function() {
        this.setSlideRate(0);
        return true;
    },
    end: function() {
        this.setSlideRate(1);
        return true;
    }
};
  1. Register the key listener in initChildren() (after button creation):
this.on('key', this.onKey);

This mirrors how BaseMenu registers its key listener at line 134 of BaseMenu.js.

Workaround

We are currently monkey-patching Slider.prototype to add the missing userActions and wrap initChildren to register the key listener.

Version

terminal-kit 3.1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions