ant-design-vue icon indicating copy to clipboard operation
ant-design-vue copied to clipboard

mentions组件支持autoSize功能

Open duoluodexiaoxiaoyuan opened this issue 1 year ago • 1 comments
trafficstars

  • [ ] I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

输入较多内容时候可以自动调节高度

What does the proposed API look like?

autoSize

duoluodexiaoxiaoyuan avatar Aug 15 '24 03:08 duoluodexiaoxiaoyuan

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Oct 15 '24 02:10 github-actions[bot]

自己本地hack了

// textarea 就是mentions 里面那个textarea
let tmp:any = null
export function autoHeight(textarea: any, minHeight = 88, maxHeight = 176) {
  const style = getComputedStyle(textarea)
  tmp = tmp || document.createElement('div')
  tmp.style.width = style.width
  tmp.style.lineHeight = style.lineHeight
  tmp.style.fontSize = style.fontSize
  tmp.style.whiteSpace = 'break-spaces'
  tmp.style.position = 'fixed'
  tmp.style.pointerEvents = 'none'
  tmp.style.wordBreak = 'break-all'
  tmp.style.opacity = '0'

  // tmp.style.top = '0'
  // tmp.style.right = '120px'
  // tmp.style.background = 'red'
  // tmp.style.zIndex = `1000`

  tmp.textContent = textarea.value
  document.body.appendChild(tmp)
  const newHeight = tmp.offsetHeight
  textarea.style.height = `${Math.min(Math.max(minHeight, newHeight), maxHeight)}px`
  //document.body.removeChild(tmp)
}

jsmgg avatar Nov 05 '24 12:11 jsmgg

自己本地hack了

// textarea 就是mentions 里面那个textarea
let tmp:any = null
export function autoHeight(textarea: any, minHeight = 88, maxHeight = 176) {
  const style = getComputedStyle(textarea)
  tmp = tmp || document.createElement('div')
  tmp.style.width = style.width
  tmp.style.lineHeight = style.lineHeight
  tmp.style.fontSize = style.fontSize
  tmp.style.whiteSpace = 'break-spaces'
  tmp.style.position = 'fixed'
  tmp.style.pointerEvents = 'none'
  tmp.style.wordBreak = 'break-all'
  tmp.style.opacity = '0'

  // tmp.style.top = '0'
  // tmp.style.right = '120px'
  // tmp.style.background = 'red'
  // tmp.style.zIndex = `1000`

  tmp.textContent = textarea.value
  document.body.appendChild(tmp)
  const newHeight = tmp.offsetHeight
  textarea.style.height = `${Math.min(Math.max(minHeight, newHeight), maxHeight)}px`
  //document.body.removeChild(tmp)
}

这是要写到node_modules下面的哪里了

duoluodexiaoxiaoyuan avatar Nov 06 '24 01:11 duoluodexiaoxiaoyuan

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Nov 07 '25 01:11 github-actions[bot]