Skip to content
This repository was archived by the owner on Aug 3, 2022. It is now read-only.
This repository was archived by the owner on Aug 3, 2022. It is now read-only.

Switch should behave like Checkbox -- some suggestions... #51

@JavaTiger13

Description

@JavaTiger13

Hello,

i like this component and i have the following enhancements to suggest:

  1. Component should not propagate events, after consumption! => e.preventDefault();

  2. Dragability for web Client unecesary with bad user responsabilty behavior
    => Should be turned off by property, eg: dragable= false // (default true)

  3. Arrow Keys LEFT and RIGHT were bound to this component, but many times needed in application for other purposes
    => should optional, I would expect like on all selectable Form Elements that SPACE would select and unselct like in a checkbox
    eg: keyboardMode= [Arrows|Space|None]
    here my contibution (not including tristate):

         case 32:
             if(this._getValue() !== null && this._getValue() === true){
                 e.preventDefault();
                 return this._setValue(false);
             } else if(this._getValue() !== null && this._getValue() === false){
                 e.preventDefault();
                 return this._setValue(true);
             } else {
                 // ignore tristate
             }
             break;
    

i also generalized the event and get rid of dedicated events for ON and OFF:
_handleToggleClick(){
if(this._disableUserInput())
return;

    if(this._getValue() !== null && this._getValue() === true) {
        this._setValue(this.props.tristate ? (this._getValue() == null) : false);
    } else  if(this._getValue() !== null && this._getValue() === false) {
        this._setValue(this.props.tristate ? (this._getValue() == null) : true);
    }

    this._setFocus();
}

(dont forget in renderLabel => onClick: this._handleToggleClick.bind(this))

  1. as the value behind the Component (excluding tristate) is true / false, the expectation of a user is the one from a checkbox / readiobutton to select / unselect by using the SPACE key, which was not supported

  2. the tabindex was not propagated, which in Formular Based Apps is a NO GO!

Switch.defaultProps = {
tabIndex: 0
}
Switch.propTypes = {
tabIndex: PropTypes.number,
}

in render()
in the wrapper Params:
tabIndex: ${tabIndex},

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