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

feat: scroll to end input element #3293

Merged
merged 11 commits into from
Jul 19, 2022

Conversation

Innei
Copy link
Contributor

@Innei Innei commented Jul 14, 2022

Signed-off-by: Innei [email protected]

closes #3280

@vercel
Copy link

vercel bot commented Jul 14, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
naive-ui ✅ Ready (Inspect) Visit Preview Jul 19, 2022 at 3:47PM (UTC)

Signed-off-by: Innei <[email protected]>
@07akioni
Copy link
Collaborator

直接给个 srollTo 吧,对 input 和 textarea 都生效,toend 太局限了

Signed-off-by: Innei <[email protected]>
Signed-off-by: Innei <[email protected]>
Comment on lines 709 to 724
function scrollToEnd (animated = true): void {
const { value: textareaEl } = textareaElRef
if (!textareaEl) {
return
}

const { scrollHeight, scrollTop, clientHeight } = textareaEl
const end = scrollHeight - clientHeight
if (end === scrollTop) {
return
}
scrollTo({
top: end,
behavior: animated ? 'smooth' : 'auto'
})
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个删了吧,别暴露这种

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为已经有能用的了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleScrollEnd () {
inputInstRef.value?.scrollTo({
behavior: 'smooth',
top: inputInstRef.value?.textareaElRef?.scrollHeight
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种不需要这么干净,写个 10000 就好了

src/input/src/Input.tsx Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add 'scrollToEnd' methods for n-input (type="textarea")
2 participants