ios 上textarea placeholder不换行的问题

发现在ios上placeholder过长时,删除内容后不换行的问题,但是重新点击textarea以后又正常了,试了一下让其重新聚焦,貌似是可以了,具体情况请具体分析,这里记录一下。

const onTaChange = (value) => {
    setContent(value)
    if ((!value || value.length === 0)) {
        if (ref){
            //重新聚焦
            ref.current.blur()
            ref.current.focus()
        }
    }
}

 

import './ques.css'
import {TextArea} from "antd-mobile";
import {useRef, useState} from "react";

export const Question = () => {

    const [content, setContent] = useState('')
    const [placeholder,setPlaceHolder] = useState('在onchange里面计算最新的字数长度,再把最大长度提取成一个state存起来,直接   【  最新长度/最大长度  】就ok了')
    const [maxLen, setMaxLen] = useState(200)

    const ref = useRef()

    const getContentCount = () => {
        return (
            <div className='ta-count-box'>
                {content ? content.length : 0}/{maxLen}
            </div>
        )
    }

    const onTaChange = (value) => {
        setContent(value)
        if ((!value || value.length === 0)) {
            if (ref){
                ref.current.blur()
                ref.current.focus()
            }
        }
    }

    return (
        <div className="que-box">
            <TextArea
                ref={ref}
                style={
  { whiteSpace: 'pre-wrap' }}
                id={'textarea'}
                autoSize
                maxLength={maxLen}
                placeholder={placeholder}
                rows={10}
                showCount={getContentCount}
                onChange={onTaChange}
            >
            </TextArea>
        </div>
    )
}

 

css:

.que-box{
    margin: 15px;
}

.ta-count-box{
    width: 100%;
    text-align: right;
}

::-webkit-input-placeholder { /* Webkit browsers*/
    white-space: pre-wrap!important;
}

:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
    color: red!important;
}

:-moz-placeholder { /* Mozilla Firefox 19+ */
    color: red!important;
}

:-ms-input-placeholder { /* Internet Explorer 10+ */
    color: red!important;
}

相关推荐

  1. ios textarea placeholder问题

    2024-01-01 06:56:02       41 阅读
  2. 【前端】html渲染\n\t\r等问题

    2024-01-01 06:56:02       37 阅读
  3. vue文本识别“\n“问题解决方式

    2024-01-01 06:56:02       37 阅读
  4. css之flex布局文本显示省略号解决方法

    2024-01-01 06:56:02       18 阅读
  5. border设置小于1px,在ios显示问题

    2024-01-01 06:56:02       36 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-01 06:56:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-01 06:56:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-01 06:56:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-01 06:56:02       18 阅读

热门阅读

  1. 分布式【4. 什么是 CAP?】

    2024-01-01 06:56:02       35 阅读
  2. c# 让文件只读

    2024-01-01 06:56:02       32 阅读
  3. Prometheus监控nginx

    2024-01-01 06:56:02       37 阅读
  4. 在Neo4j中实现推荐算法

    2024-01-01 06:56:02       37 阅读
  5. 数据挖掘与知识发现:解析关键概念

    2024-01-01 06:56:02       25 阅读
  6. 常用的几种包管理器 npm yarn cnpm pnpm 安装

    2024-01-01 06:56:02       41 阅读
  7. 计算机基础--Linux详解

    2024-01-01 06:56:02       33 阅读
  8. 第82讲:MySQL Binlog日志的滚动

    2024-01-01 06:56:02       35 阅读
  9. git 命令

    2024-01-01 06:56:02       38 阅读
  10. yii2 mysql重连机制

    2024-01-01 06:56:02       37 阅读
  11. 基于SpringBoot的电影购票系统

    2024-01-01 06:56:02       36 阅读
  12. 【算法】数论---快速幂

    2024-01-01 06:56:02       42 阅读
  13. 剑指offer题解合集——Week2day6

    2024-01-01 06:56:02       42 阅读
  14. C语言之冒泡排序

    2024-01-01 06:56:02       34 阅读
  15. SQL高级:存储过程和触发器

    2024-01-01 06:56:02       36 阅读