Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dialog&Input] Dialog中引入Input组件,从Input中间输入光标会跳转到最后 #2484

Closed
cjSound opened this issue Sep 1, 2023 · 3 comments · Fixed by #2485
Closed
Labels
to be published fixed, not be published

Comments

@cjSound
Copy link

cjSound commented Sep 1, 2023

tdesign-react 版本

1.2.4

重现链接

https://stackblitz.com/edit/react-v8nwsw?file=src%2Fdemo.jsx,src%2Findex.css

重现步骤

复现步骤

Input单独使用是正常的,当Input位于Dialog内,会出现光标异常

1、定义一个普通的Dialog组件
2、组件内引入Input组件,设置value和OnChange
3、打开Dialog弹窗
4、从Input中间输入值
5、输入任意值光标跳转到Input最后

示例代码

export default function BasicUsage() {
  const [visible, setVisible] = useState(false);
  const [value, onChange] = useState('Welcome to TDesign');

  const handleClick = () => {
    setVisible(true);
  };
  const onConfirm = (context) => {
    console.log('点击了确认按钮', context);
    setVisible(false);
  };
  const onCancel = (context) => {
    console.log('点击了取消按钮', context);
  };
  const onClickCloseBtn = (context) => {
    console.log('点击了关闭按钮', context);
  };
  const onKeydownEsc = (context) => {
    console.log('按下了ESC', context);
  };
  const onClickOverlay = (context) => {
    console.log('点击了蒙层', context);
  };
  const handleClose = (context) => {
    console.log('关闭弹窗,点击关闭按钮、按下ESC、点击蒙层等触发', context);
    setVisible(false);
  };
  return (
    <>
      <Button theme="primary" onClick={handleClick}>
        Open Modal
      </Button>
      <Input
        placeholder="请输入内容(有默认值)"
        value={value}
        onChange={(value) => {
          onChange(value);
        }}
        onEnter={(value) => {
          console.log(value);
        }}
      />
      <Dialog
        header="Basic Modal"
        visible={visible}
        confirmOnEnter
        onClose={handleClose}
        onConfirm={onConfirm}
        onCancel={onCancel}
        onEscKeydown={onKeydownEsc}
        onCloseBtnClick={onClickCloseBtn}
        onOverlayClick={onClickOverlay}
      >
        <p>This is a dialog</p>
        <Input
          placeholder="请输入内容(有默认值)"
          value={value}
          onChange={(value) => {
            onChange(value);
          }}
        />
      </Dialog>
    </>
  );
}

期望结果

光标不要乱跳,保持当前位置

实际结果

光标跳转到最后,影响输入和体验

框架版本

No response

浏览器版本

No response

系统版本

No response

Node版本

No response

补充说明

No response

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

👋 @cjSound,感谢给 TDesign 提出了 issue。
请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。

@HaixingOoO
Copy link
Collaborator

问题:

截屏2023-09-01 17 57 15

1.发现问题是因为在光标中间输入拼音,光标是不会跳到后面的(这里我也觉得有点怪)

2.然后发现是这里调用的函数,把props的children每次都重新渲染覆盖,导致input的value每次传进来input.value = props.value(input的value又是和props.value相等的),所以导致光标一直跳到后面

解决方案:

截屏2023-09-01 18 18 09 截屏2023-09-01 18 18 54

1.把props.children这样传入是可以解决问题的

@uyarn
Copy link
Collaborator

uyarn commented Nov 15, 2023

fixed in 1.3.1

@uyarn uyarn closed this as completed Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to be published fixed, not be published
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants