Is the text in the React chat application too lengthy causing a bug problem?

In my chat application built with React, I am facing an issue where if a user types more than 100 characters, the message gets cut off. How can I fix this problem? Please refer to the image below for reference.

https://i.sstatic.net/DLNyH.png

{Object.keys(messages).map((keyName) => (
    messages[keyName].isOut 
        ? <div>
            <div className="sender1">
                {messages[keyName].content.text}
                <span className="timestamp1" > {messages[keyName].date}</span>
            </div>
        </div>
        : <div>
            <p className="receiver1" >
                {messages[keyName].content.text}
                <span className="timestamp1" > {messages[keyName].date}</span>
            </p>
        </div>
))}
.sender1{
  width: fit-content;
  padding: 15px;
  border-radius: 8px;
  margin: 10px;
  min-width: 60px;
  padding-bottom: 26px;
  position: relative;
  text-align: right;
  margin-left: auto;
  background-color: #dcf8c6;
}

.receiver1{
  background-color: whitesmoke;
  width: fit-content;
  padding: 15px;
  border-radius: 8px;
  margin: 10px;
  min-width: 60px;
  padding-bottom: 26px;
  position: relative;
}

Answer №1

I successfully addressed the issue with word-breaking by implementing 'break-all', and it is currently functioning perfectly.

Answer №2

Utilizing the max-width property can be beneficial. For example:

.sender1{
  max-width:300px; //sample size
  word-break: break-all;
  width: fit-content;
  padding: 15px;
  border-radius: 8px;
  margin: 10px;
  min-width: 60px;
  padding-bottom: 26px;
  position: relative;
  text-align: right;
  margin-left: auto;
  background-color: #dcf8c6;
}

.receiver1{
  max-width:300px; //sample size
  word-break: break-all;
  background-color: whitesmoke;
  width: fit-content;
  padding: 15px;
  border-radius: 8px;
  margin: 10px;
  min-width: 60px;
  padding-bottom: 26px;
  position: relative;
}

Consider setting text-align to left for the receiver1 element.

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

sharing functions across distinct components in react without directly passing between parent and child

I have a query about passing functions between components that are not related in a parent/child hierarchy. Here is the structure inside my App. function App() { return ( <div className="App"> <Header/> <Pfl /> ...

What is the method to obtain the dimensions of the browser window using JavaScript?

In my JavaScript code, I am trying to retrieve the browser window size and then set the size of a div element accordingly. I have two div elements that should adjust based on the window size. For example, if the window size is 568px, div1 should be 38% of ...

What is the best way to input data into nedb across various lines?

There is a requirement to store each element of an array into separate lines while saving it in the NEDB database. The idea is to add "\r\n" after every element, like this: Currently, I am doing the following: usernames = ["name1","name2","name3 ...

Unsupported MIME format

I'm encountering an issue where my stylesheet is not applying to my handlebars. It was working fine yesterday, but today I'm seeing a MIME error and I'm unsure of the reason behind it. Any assistance would be greatly appreciated. Server Cod ...

What is the method for embedding the creation date of a page within a paragraph on Wagtail?

Whenever a page is created in the admin panel of Wagtail, it automatically displays how much time has elapsed since its creation. https://i.stack.imgur.com/6InSV.png I am looking to include the timestamp of the page's creation within a paragraph in ...

Is it possible to create a replicating text box in AngularJS that multiplies when entering input

I am experimenting with creating a sequence of text boxes that dynamically generate new empty text boxes as the user enters information into each one. Each text box is required to have an ng-model value associated with it, and they should all be generated ...

Create a container-fluid design in Bootstrap with various colors

I am aiming to create a design with a fluid container featuring different background colors on each side, separated by two columns within the container. I have visualized it in this image - do you think it is feasible? https://i.stack.imgur.com/KRc2Q.pn ...

Experiencing difficulties replicating two auto-scrolling divs

I have implemented a script to automatically slide two different divs. Here is the code I am using: The HTML: <div id="gallery"> <div id="slider" style="width: 6000px; left: -500px;"> <div><aside class="widget widget_testimoni ...

Encountered a JavaScript loading error during the installation of Sourcetree on a Windows 7

Encountering an error during the installation of Sourcetree on a Windows 7 (32-bit) system. Atlassian JavaScript load error We encountered issues while trying to load scripts. Please ensure that your network settings permit downloading scripts from this ...

Retrieve data from multiple inputs with the same name in a Spring MVC form

I have a JSP page with input fields that can be dynamically added or removed. I need to map these input fields to the @ModelAttributes in Spring MVC, but I'm unsure of how to do this. I want to submit a form that includes: <form enctype="multipar ...

unable to respond when clicking an angularjs link

I'm facing an issue where I can't get a link to respond to click events in AngularJS. When I click on the anchor link, nothing happens. Here is a snippet of the AngularJS script: <script data-require="<a href="/cdn-cgi/l/email-protection" ...

Using Jquery and AJAX to dynamically fill out an HTML form based on dropdown selection

My goal is to populate a form on my webpage with information pulled from a MySQL database using the ID of the drop-down option as the criteria in the SQL statement. The approach I have considered involves storing this information in $_SESSION['formBoo ...

Jest (23.5.0) in WebStorm (2018.2.3) is encountering an issue with the unimplemented function or method "xxx"

Lately, I've encountered an issue with Jest (23.5.0) and WebStorm (2018.2.3) intellisense. Whenever I try to use any of the Jest methods like toHaveBeenCalledWith or toHaveLength, I consistently receive an error stating Unresolved function or method & ...

Encountering an error while attempting to load the jQuery script: TypeError - $.fn.appear.run is not a

I have included an animation script for CSS in my markup, but I am encountering the following error: TypeError: $.fn.appear.run is not a function Does anyone know why this is happening and how I can resolve it? /* * CSS3 Animate it * Copyright (c) 2 ...

Exploring the implementation of Generic types within a function's body

When trying to encapsulate logic inside the OrderGuard component (which can handle two types of orders: CheckinOrder or Checkout order), I encounter an issue when passing the order to the orderLoad callback in TypeScript. The error message states that "Ch ...

"Enhance Your Coding Experience with Visual Studio Code - TypeScript Definitions Catered

I am currently working on developing a basic web application using Node.js and Express. I have successfully installed both definitions using tsd following the steps outlined in this guide. When I run tsd query mongodb --action install, I do not encounter ...

Identifying Oversized Files on Safari Mobile: A Guide to Detecting Ignored Large Files in

Mobile browsers such as Safari have a tendency to ignore large files when passed in through the <input type="file">. For example, testing with a 10mb image file results in no trigger of any events - no change, no error, nothing. The user action is si ...

The AJAX response is incorrect due to a PHP request, leading to the reloading

Whenever the 'signup' button is clicked, a function in my code initiates an HTML switch. The issue I am facing arises when I test for incorrect email or password during sign up. While I can successfully verify the data, it still loads the previou ...

substitute placeholders when clicked in react applications

I'm still learning the ropes of React, especially when it comes to dealing with states. Currently, I have an accordion component set up with multiple items and a list of text that I need to iterate through. Here's a snippet of the code: Accord ...

What is the best way to ensure that all rows in flexbox have the same number and dimensions as the first row?

My objective with flexbox was to evenly distribute the text across the width of the page. When I say 'evenly distributed', I mean: If there are 3 sections, the center of the text in each section should be at fifths of the webpage width. This is ...