Steps for inserting an icon tag within a text input field

In this section, I have created a div class that contains an image tag to display the profile picture. Following that, there is a <TextInput> element styled using CSS. Outside of the <TextInput/>, there is a custom button for submitting posts.

I am looking to incorporate the <IoMdSend/> icon inside the text input. However, when I attempt to do so, it results in errors or the icon does not appear correctly on the frontend; sometimes it even ends up below the text input. How can I successfully add this icon here?

<div className="w-full flex items-center justify-between gap-2 py-4 border-b border-[#66666645]">
                <img
                  src={user?.profileUrl ?? NoProfile}
                  alt="User Image"
                  className="w-14 h-14 rounded-full object-cover"
                />
                <TextInput
                  styles="w-full rounded-full py-5 px-4 pr-12 position: relative" // Add position: relative for child elements
                  placeholder="What's on your mind...."
                  name="description"
                  register={register("description", {
                    required: "Write something about post",
                  })}
                  error={errors.description ? errors.description.message : ""}
                >
                </TextInput>
                {/* <IoMdSend
                  style={{
                    fontSize: "2.2rem",
                    color: "#ccc",
                  }}
                /> */}
                {posting ? (
                  <Loading />
                ) : (
                  <CustomButton
                    type="submit"
                    title="Post"
                    containerStyles="bg-[#0444a4] text-white py-1 px-4 rounded-full font-semibold      text-sm"
                  />
                )}
              </div>

>

Answer №1

If you're looking to render two divs in React, consider using a React Fragment. Here's an example:

The TextInput component should be structured like this for it to work correctly:

<React.Fragment>
  <div className="text-input">
    .. do something
  </div>
  
  <IoMdSend
    style={{
      fontSize: "2.2rem",
      color: "#ccc",
    }}
  />
</React.Fragment>

By updating the code as shown above, you'll ensure proper functionality of the TextInput component.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Update the text content when clicked in React

For the onClick event, I am attempting to edit the entered text using the enableEdit function. My goal is to trigger the function when double-clicking on the entered text. Here is a snippet of my code: class App extends React.Component { const ...

Experiencing issues with Sendinblue integration on Vercel's production environment

It's the typical scenario - everything runs smoothly during development but throws errors in production without any clear explanation. My NextJS app is deployed on Vercel. I attempted to incorporate async await into my code based on a recommendation ...

Error: In node.JS / express, attempting to post to a route results in a TypeError stating that the property 'username' is undefined

I am encountering a Type Error when trying to post to my exercises. Below is the code for my exercises route: const router = require("express").Router(); let Exercise = require("../models/exercise.model.js"); //retrieve all exercises r ...

Accept a JSON-sending POST request in a JSP file via JavaScript

I have developed an HTML page with an input field. Using javascript, I extract the input value, convert it into JSON format, and attempt to send it through ajax. Additionally, I have a JSP application where a Java method processes this JSON data to store i ...

On the hunt for a Laravel 8 application using Jetstream and Inertia within the DOM!

Hey there, I'm currently in the process of transitioning our Vuetify app to Laravel 8, Jetstream, and the inertia stack. While going through ./resources/js/app.js, I came across this line: const app = document.getElementById('app'); This c ...

Press the Instagram Follow Buttons by utilizing Selenium with Java

click here for image description Hello, I am currently working on automating the process of clicking follow buttons using Java. However, I'm encountering difficulties when trying to use JavascriptExecutor within a for loop. Below is the code snippet ...

"Encountering a subpar response with Volley in Android

I'm attempting to send a basic request to my server and display the response in a textbox. The code on my server simply echoes "hello." My application consists of a button to send the request, along with two textboxes - one for displaying responses an ...

Tips for positioning button to the right of a text box in Bootstrap

Is there a way to align my button with my text boxes so that the right sides form a straight line? I've been struggling to achieve this without using margin-left (as it only works for one screen size). https://i.sstatic.net/RrEYV.png I attempted to ...

What makes componentDidMount() the optimal choice for analyzing user authentication?

I'm currently learning about authentication and I'm trying to grasp the concept behind this code snippet: componentDidMount() { this.props.firebase.auth.onAuthStateChanged(authUser => { authUser ? this.setState({ authUser }) ...

Dealing with JWT management in the absence of Cookies

After doing some research on JSON Web Token (which is a new concept to me), I have learned about its secure mechanism for transmitting information between parties without the need for server Sessions. Currently, I am in the process of building a web app f ...

Is it beneficial to separate React and WebAPI into two distinct projects?

After spending 4 years in Asp.Net MVC and JQuery, I am looking to take the next step and transition to .Net Core 2, WebAPI, and React. I have been following various how-tos and tutorials, but what puzzles me is why every tutorial suggests adding React dir ...

Which specific technological platform or framework would be most suitable for constructing a similar project?

https://i.stack.imgur.com/LL1g9.png Looking at the image provided, my goal is to allow users to navigate between pages on the Home page without having to refresh the entire browser window. I believe this can be achieved using Ajax technology, am I correct ...

Every time I try to use `sudo npm install`, I encounter an access

I recently transferred my ionic project from machine1 to machine2 using git, but I encountered an error when checking my Ionic info: [ERROR] Error with ./node_modules/@ionic/app-scripts/package.json file: FILE_NOT_FOUND cli packages: (/usr/local/lib/node ...

Spring Security does not generate an error if the authorization header is missing following a login using AngularJS

Working on implementing HTTP Basic Authentication using Spring Security and Angular JS by including the Authorization header in $http headers: const headers = { authorization: "Basic " + btoa(this.login + ":" + this.password) }; this._$http.get("user ...

A method for utilizing wildcards in conjunction with the .load function

Currently, I am utilizing jquery, jquery mobile, js, html, and css within Phonegap to develop my android/ios application. However, my understanding of js & jquery is somewhat limited. In my index.html file, I use .load to load other html files into s ...

Error message: The requested resource in Golang does not have an 'Access-Control-Allow-Origin' header present, which means that the origin 'null' is not permitted to access it

I am currently experimenting with checking if a domain A client can send a domain B cookie to domain B. Here is the Go code I am using: package main import ( "fmt" "net/http" "log" "time" "encoding/json" ) func setCookie(w http.Resp ...

Troubleshooting: jQuery click event not functioning properly on Internet Explorer versions 7 and

Why doesn't the following code work in IE7 or IE8? Is this a bug? Surprisingly, it works perfectly fine in IE6! http://jsfiddle.net/zgSmT/ ...

Tips on expanding a list within a div after the content in the list is complete

I find it frustrating to always manually enter fixed widths for divs depending on the number of letters in a li tag. <div> <ul> <li><a href="#">Home</a></li> <li><a href="#">Information</a>&l ...

Adjusting the background opacity when the sidebar is open in a React + Typescript project

I am currently working on customizing a sidebar using the react-pro-sidebar library along with React and Typescript. The sidebar layout seems to be in order, but I am facing difficulty in adjusting the background color of the rest of the screen when the si ...

Tips for positioning the avatar to the right along with other links?

I've encountered various methods to align text or an image to the right, but I'm having trouble aligning a basic avatar with some text. It used to work before I switched to material-ui-next, and now I can't seem to get them aligned properly. ...