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

VirtualInput 的 keyboard参数的getContainer失效 #6318

Closed
TivonJJ opened this issue Aug 15, 2023 · 6 comments
Closed

VirtualInput 的 keyboard参数的getContainer失效 #6318

TivonJJ opened this issue Aug 15, 2023 · 6 comments
Labels

Comments

@TivonJJ
Copy link

TivonJJ commented Aug 15, 2023

Version of antd-mobile

v5.32.0

Operating system and its version

No response

Browser and its version

All

Sandbox to reproduce

No response

What happened?

该代码设置后keyboard还是渲染在了子元素内,未append到body。 这样键盘可能会继承input的一些自定义样式。

<VirtualInput
  keyboard={
    <NumberKeyboard
      className={classnames('NumberKeyboard', keyboardClassName)}
      getContainer={document.body}
    />
  }
/>

https://mobile.ant.design/zh/components/number-keyboard

https://mobile.ant.design/zh/components/virtual-input

Relevant log output

No response

@TivonJJ TivonJJ added the bug label Aug 15, 2023
@1587315093
Copy link
Contributor

1587315093 commented Aug 16, 2023

97398a0

应该是预期行为?

@TivonJJ
Copy link
Author

TivonJJ commented Aug 16, 2023

97398a0

应该是预期行为?

为什么会如此做? 我觉得这个还是开放可控更好,因为这种浮窗在子组件内可能会产生很多不必要的麻烦。

@1587315093
Copy link
Contributor

1587315093 commented Aug 16, 2023

97398a0
应该是预期行为?

为什么会如此做? 我觉得这个还是开放可控更好,因为这种浮窗在子组件内可能会产生很多不必要的麻烦。

刻意加的代码总有它的道理~ 看commit msg意思是 防止长按使输入元素丢失...

@TivonJJ
Copy link
Author

TivonJJ commented Aug 16, 2023

97398a0
应该是预期行为?

为什么会如此做? 我觉得这个还是开放可控更好,因为这种浮窗在子组件内可能会产生很多不必要的麻烦。

刻意加的代码总有它的道理~ 看commit msg意思是 防止长按使输入元素丢失...

然而那个问题并没有完全解决

@TivonJJ
Copy link
Author

TivonJJ commented Aug 16, 2023

曲线解决了此问题

const NumberKeyboardWithContainer = (
    props: Omit<NumberKeyboardProps, 'getContainer'> & {
        container: NumberKeyboardProps['getContainer'];
    },
) => {
    return <NumberKeyboard {...props} getContainer={props.container} />;
};

<VirtualInput
            keyboard={
                <NumberKeyboardWithContainer
                    data-key={uniqueKey}
                    className={classnames('numberkeyboard', keyboardClassName)}
                    container={getContainer}
                    {...restKeyboardProps}
                />
            }
        />

@TivonJJ TivonJJ closed this as completed Aug 16, 2023
@1587315093
Copy link
Contributor

曲线解决了此问题

const NumberKeyboardWithContainer = (
    props: Omit<NumberKeyboardProps, 'getContainer'> & {
        container: NumberKeyboardProps['getContainer'];
    },
) => {
    return <NumberKeyboard {...props} getContainer={props.container} />;
};

<VirtualInput
            keyboard={
                <NumberKeyboardWithContainer
                    data-key={uniqueKey}
                    className={classnames('numberkeyboard', keyboardClassName)}
                    container={getContainer}
                    {...restKeyboardProps}
                />
            }
        />

思路挺好~

那个问题没解决能说说吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants