How to use the rc-util/lib/KeyCode.UP 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 / cascader / src / Cascader.tsx View on Github external
const { children } = this.props;
    // https://github.com/ant-design/ant-design/issues/6717
    // Don't bind keyboard support when children specify the onKeyDown
    if (children && children.props.onKeyDown) {
      children.props.onKeyDown(e);
      return;
    }
    const activeValue = [...this.state.activeValue];
    const currentLevel = activeValue.length - 1 < 0 ? 0 : activeValue.length - 1;
    const currentOptions = this.getCurrentLevelOptions();
    const currentIndex = currentOptions
      .map(o => o[this.getFieldName('value')])
      .indexOf(activeValue[currentLevel]);
    if (
      e.keyCode !== KeyCode.DOWN &&
      e.keyCode !== KeyCode.UP &&
      e.keyCode !== KeyCode.LEFT &&
      e.keyCode !== KeyCode.RIGHT &&
      e.keyCode !== KeyCode.ENTER &&
      e.keyCode !== KeyCode.SPACE &&
      e.keyCode !== KeyCode.BACKSPACE &&
      e.keyCode !== KeyCode.ESC &&
      e.keyCode !== KeyCode.TAB
    ) {
      return;
    }
    // Press any keys above to reopen menu
    if (
      !this.state.popupVisible &&
      e.keyCode !== KeyCode.BACKSPACE &&
      e.keyCode !== KeyCode.LEFT &&
      e.keyCode !== KeyCode.RIGHT &&
github react-component / cascader / src / Cascader.tsx View on Github external
) {
      return;
    }
    // Press any keys above to reopen menu
    if (
      !this.state.popupVisible &&
      e.keyCode !== KeyCode.BACKSPACE &&
      e.keyCode !== KeyCode.LEFT &&
      e.keyCode !== KeyCode.RIGHT &&
      e.keyCode !== KeyCode.ESC &&
      e.keyCode !== KeyCode.TAB
    ) {
      this.setPopupVisible(true);
      return;
    }
    if (e.keyCode === KeyCode.DOWN || e.keyCode === KeyCode.UP) {
      e.preventDefault();
      let nextIndex = currentIndex;
      if (nextIndex !== -1) {
        if (e.keyCode === KeyCode.DOWN) {
          nextIndex += 1;
          nextIndex = nextIndex >= currentOptions.length ? 0 : nextIndex;
        } else {
          nextIndex -= 1;
          nextIndex = nextIndex < 0 ? currentOptions.length - 1 : nextIndex;
        }
      } else {
        nextIndex = 0;
      }
      activeValue[currentLevel] = currentOptions[nextIndex][this.getFieldName('value')];
    } else if (e.keyCode === KeyCode.LEFT || e.keyCode === KeyCode.BACKSPACE) {
      e.preventDefault();
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:
        if (ctrlKey) {
          this.goTime(1, 'years');
        } else {
          this.goTime(1, 'days');
github react-component / calendar / tests / MonthCalendar.spec.js View on Github external
it('UP', () => {
      wrapper.simulate('keydown', {
        keyCode: keyCode.UP,
      });
      expect(wrapper.state().value.month()).toBe(1);
    });
github react-component / input-number / tests / index.js View on Github external
render() {
          return ( `$ ${num} boeing 737`}
            parser={num => num.toString().split(' ')[1]}
          />);
        },
      });
      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 / tests / SubMenu.spec.js View on Github external
const wrapper = mount(createMenu());
      const titles = wrapper.find('.rc-menu-submenu-title');

      titles
        .first()
        .simulate('mouseEnter')
        .simulate('keyDown', { keyCode: KeyCode.LEFT })
        .simulate('keyDown', { keyCode: KeyCode.DOWN });
      expect(
        wrapper
          .find('.rc-menu-submenu')
          .last()
          .is('.rc-menu-submenu-active'),
      ).toBe(true);

      titles.last().simulate('keyDown', { keyCode: KeyCode.UP });
      expect(
        wrapper
          .find('.rc-menu-submenu')
          .first()
          .is('.rc-menu-submenu-active'),
      ).toBe(true);
    });
github m430 / antd-pro-toolkit / components / TabCascader / index.tsx View on Github external
handleKeyDown = (e: React.KeyboardEvent) => {
    const { selectedItems } = this.state;
    const { which } = e;

    if (which === KeyCode.ESC) {
      this.onToggleDropdown();
      this.setState({
        inputVal: this.renderValue(selectedItems)
      });
      return;
    }

    if (which === KeyCode.UP || which === KeyCode.DOWN) {
      e.preventDefault();
    }

    if (this.listRef.current) {
      this.listRef.current.onKeyDown(e);
    }
  }
github antvis / x6 / packages / x6-components / src / scrollbar / index.tsx View on Github external
} else {
      switch (keyCode) {
        case keys.SPACE:
          if (e.shiftKey) {
            direction = -1
          } else {
            direction = 1
          }
          break

        case keys.HOME:
          direction = -1
          distance = contentSize
          break

        case keys.UP:
          direction = -1
          break

        case keys.DOWN:
          direction = 1
          break

        case keys.PAGE_UP:
          direction = -1
          distance = containerSize
          break

        case keys.PAGE_DOWN:
          direction = 1
          distance = containerSize
          break
github react-component / select / src / Selector / index.tsx View on Github external
> = event => {
    const { which } = event;

    if (which === KeyCode.UP || which === KeyCode.DOWN) {
      event.preventDefault();
    }

    if (onInputKeyDown) {
      onInputKeyDown(event);
    }

    if (
      ![KeyCode.SHIFT, KeyCode.TAB, KeyCode.BACKSPACE, KeyCode.ESC].includes(
        which,
      )
    ) {
      onToggleOpen(true);
    }
  };
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:
        value = stateValue.clone();
        if (ctrlKey) {
          value.add(1, 'years');
        } else {