How to use the rc-util/lib/KeyCode.DOWN function in rc-util

To help you get started, we’ve selected a few rc-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github react-component / calendar / src / Calendar.jsx View on Github external
onKeyDown = (event) => {
    if (event.target.nodeName.toLowerCase() === 'input') {
      return undefined;
    }
    const keyCode = event.keyCode;
    // mac
    const ctrlKey = event.ctrlKey || event.metaKey;
    const { disabledDate } = this.props;
    const { value } = this.state;
    switch (keyCode) {
      case KeyCode.DOWN:
        this.goTime(1, 'weeks');
        event.preventDefault();
        return 1;
      case KeyCode.UP:
        this.goTime(-1, 'weeks');
        event.preventDefault();
        return 1;
      case KeyCode.LEFT:
        if (ctrlKey) {
          this.goTime(-1, 'years');
        } else {
          this.goTime(-1, 'days');
        }
        event.preventDefault();
        return 1;
      case KeyCode.RIGHT:
github react-component / select / src / OptionList.tsx View on Github external
onKeyDown: event => {
      const { which } = event;
      switch (which) {
        // >>> Arrow keys
        case KeyCode.UP:
        case KeyCode.DOWN: {
          let offset = 0;
          if (which === KeyCode.UP) {
            offset = -1;
          } else if (which === KeyCode.DOWN) {
            offset = 1;
          }

          if (offset !== 0) {
            const nextActiveIndex = getEnabledActiveIndex(
              activeIndex + offset,
              offset,
            );
            scrollIntoView(nextActiveIndex);
            setActive(nextActiveIndex);
          }

          break;
        }

        // >>> Select
github react-component / select / tests / Select.spec.tsx View on Github external
expect(instance.blurTimer).toBeTruthy();
      instance.componentWillUnmount();
      expect(instance.blurTimer).toBe(null);
    });

    it('clear dropdownContainer', () => {
      instance.getDropdownContainer();

      expect(instance.dropdownContainer).toBeTruthy();
      instance.componentWillUnmount();
      expect(instance.dropdownContainer).toBe(null);
    });
  });

  [KeyCode.ENTER, KeyCode.DOWN].forEach(keyCode => {
    it('open on key press', () => {
      const wrapper = mount<select>(</select>);
      wrapper.find('.rc-select-selection').simulate('keyDown', { keyCode });
      expect(wrapper.state().open).toBe(true);
    });
  });

  it('pass event to input', () =&gt; {
    const wrapper = mount<select>(</select>);
    wrapper.instance().onInputKeyDown = jest.fn();
    wrapper.find('.rc-select').simulate('click');
    wrapper.find('.rc-select-selection').simulate('keyDown');

    expect(wrapper.instance().onInputKeyDown).toBeCalled();
  });
github react-component / input-number / tests / index.js View on Github external
step={1}
            defaultValue={5}
            useTouch
            formatter={num =&gt; `$ ${num} boeing 737`}
            parser={num =&gt; num.toString().split(' ')[1]}
          /&gt;);
        },
      });
      example = ReactDOM.render(, container);
      inputNumber = example.refs.inputNum;
      inputElement = ReactDOM.findDOMNode(inputNumber.input);
      Simulate.focus(inputElement);
      Simulate.keyDown(inputElement, { keyCode: keyCode.UP });
      expect(inputNumber.state.value).to.be(6);
      expect(inputElement.value).to.be('$ 6 boeing 737');
      Simulate.keyDown(inputElement, { keyCode: keyCode.DOWN });
      expect(inputNumber.state.value).to.be(5);
      expect(inputElement.value).to.be('$ 5 boeing 737');
      Simulate.touchStart(ReactDOM.findDOMNode(inputNumber.upHandler));
      expect(inputNumber.state.value).to.be(6);
      expect(inputElement.value).to.be('$ 6 boeing 737');
    });
  });
github react-component / menu / src / SubMenu.jsx View on Github external
}
    if (keyCode === KeyCode.LEFT) {
      let handled;
      if (isOpen) {
        handled = menu.onKeyDown(e);
      } else {
        return undefined;
      }
      if (!handled) {
        this.triggerOpenChange(false);
        handled = true;
      }
      return handled;
    }

    if (isOpen && (keyCode === KeyCode.UP || keyCode === KeyCode.DOWN)) {
      return menu.onKeyDown(e);
    }
  };
github react-component / menu / src / SubMenu.tsx View on Github external
}
    if (keyCode === KeyCode.LEFT) {
      let handled: boolean;
      if (isOpen) {
        handled = menu.onKeyDown(e);
      } else {
        return undefined;
      }
      if (!handled) {
        this.triggerOpenChange(false);
        handled = true;
      }
      return handled;
    }

    if (isOpen && (keyCode === KeyCode.UP || keyCode === KeyCode.DOWN)) {
      return menu.onKeyDown(e);
    }

    return undefined;
  };
github react-component / menu / src / MenuMixin.js View on Github external
onKeyDown(e, callback) {
    const keyCode = e.keyCode;
    let handled;
    this.getFlatInstanceArray().forEach((obj) => {
      if (obj && obj.props.active && obj.onKeyDown) {
        handled = obj.onKeyDown(e);
      }
    });
    if (handled) {
      return 1;
    }
    let activeItem = null;
    if (keyCode === KeyCode.UP || keyCode === KeyCode.DOWN) {
      activeItem = this.step(keyCode === KeyCode.UP ? -1 : 1);
    }
    if (activeItem) {
      e.preventDefault();
      updateActiveKey(this.getStore(), this.getEventKey(), activeItem.props.eventKey);

      if (typeof callback === 'function') {
        callback(activeItem);
      }

      return 1;
    } else if (activeItem === undefined) {
      e.preventDefault();
      updateActiveKey(this.getStore(), this.getEventKey(), null);
      return 1;
    }
github react-component / calendar / src / Picker.tsx View on Github external
onKeyDown = event => {
    if (!this.state.open && (event.keyCode === KeyCode.DOWN || event.keyCode === KeyCode.ENTER)) {
      this.open();
      event.preventDefault();
    }
  };
github iuap-design / bee.tinper.org / tinper-bee / bee-datepicker / src / rc-calendar / MonthCalendar.jsx View on Github external
onKeyDown = (event) => {
    if (event.target.nodeName.toLowerCase() === 'input') {
      return undefined;
    }else{
      this.props.onKeyDown&&this.props.onKeyDown(event);
    }
    const keyCode = event.keyCode;
    const ctrlKey = event.ctrlKey || event.metaKey;
    const stateValue = this.state.value;
    const { disabledDate } = this.props;
    let value = stateValue;
    switch (keyCode) {
      case KeyCode.DOWN:
        value = stateValue.clone();
        value.add(3, 'months');
        break;
      case KeyCode.UP:
        value = stateValue.clone();
        value.add(-3, 'months');
        break;
      case KeyCode.LEFT:
        value = stateValue.clone();
        if (ctrlKey) {
          value.add(-1, 'years');
        } else {
          value.add(-1, 'months');
        }
        break;
      case KeyCode.RIGHT:
github react-component / calendar / src / MonthCalendar.tsx View on Github external
onKeyDown = event => {
    const { keyCode } = event;
    const ctrlKey = event.ctrlKey || event.metaKey;
    const stateValue = this.state.value;
    const { disabledDate } = this.props;
    let value = stateValue;
    switch (keyCode) {
      case KeyCode.DOWN:
        value = stateValue.clone();
        value.add(3, 'months');
        break;
      case KeyCode.UP:
        value = stateValue.clone();
        value.add(-3, 'months');
        break;
      case KeyCode.LEFT:
        value = stateValue.clone();
        if (ctrlKey) {
          value.add(-1, 'years');
        } else {
          value.add(-1, 'months');
        }
        break;
      case KeyCode.RIGHT: