This article example shares the specific code for manually implementing an input box component for your reference. The specific content is as follows backgroundIn taro h5, I want to implement an input box with the following style: question:There is no component of this style in taro component and taro-ui component. Taro h5 does not support modifying the style of placeholder. I tried to implement an input component myself, which can define the style more flexibly. accomplishjs code import Taro, { Component } from '@tarojs/taro'; import { View } from '@tarojs/components'; import { AtIcon } from 'taro-ui'; import './index.scss'; /** * @description Manually implement an input box component* @param placeholder: String Customize the placeholder in the input box* @param onClickSearch: Function Get input content callback*/ class BaseInput extends Component { componentDidMount() { //Input box focus document.querySelector('.search').focus(); } handleSearch = () => { //Get the content of the input box const value = document.querySelector('.search').innerText; this.props.onClickSearch && this.props.onClickSearch(value); }; render() { const { placeholder = 'Please enter' } = this.props; return ( <View className="base_input"> <View className="my_search"> <AtIcon value="search" color="#999" className="search_icon" onClick={this.handleSearch} /> {/* contenteditable can control whether a div can be edited*/} <View className="search" contenteditable placeholder={placeholder} ></View> </View> </View> ); } } export default BaseInput; scss code .base_input { .my_search { box-sizing: border-box; width: 690px; height: 56px; line-height: 56px; border-radius: 28px; margin: 12px auto; background: #f8f8f8; display: flex; .search_icon { width: 30px; height: 30px; margin-left: 20px; margin-right: 18px; } .search { width: 560px; padding: 0px 18px; background: #f8f8f8; height: 56px; color: #999; font-size: 28px; font-weight: 400; &:empty::after { content: attr(placeholder); } } } } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Method of realizing automated deployment based on Docker+Jenkins
>>: MySQL multi-table query detailed explanation
Tip: The following operations are all performed u...
Regarding uninstalling the previously installed v...
wangEditor is a web rich text editor developed ba...
Table of contents Thoughts triggered by an online...
This article example shares the specific code of ...
The code looks like this: SELECT @i:=@i+1 rowNum,...
1. 85% of ads go unread <br />Interpretatio...
Refer to the tutorial on setting up FTP server in...
This article shares with you the installation tut...
Taking Windows as an example, Linux is actually t...
This old question has troubled countless front-end...
This article shares the specific code of using ca...
Table of contents 1. Live broadcast effect 2. Ste...
Table of contents 1: Prepare https certificate 2:...
In Linux systems, especially server systems, it i...