A step-by-step guide to displaying a list with material icons in a React JS application utilizing the Material

I tried implementing a dropdown list with Material-UI, including an icon on the left side. However, after following the documentation and adding the code for the icon, the dropdown list stopped working.

 InputProps={{
            startAdornment: (
              <InputAdornment position="start">
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  width="60"
                  zoomAndPan="magnify"
                  viewBox="0 0 45 44.999999"
                  height="60"
                  preserveAspectRatio="xMidYMid meet"
                  version="1.0"
                  className="fill-jacarta-700 dark:fill-jacarta-100 mr-1 h-6 w-6 transition-colors group-hover:fill-white"
                >
                  <defs>
                    <clipPath id="d11c128308">
                      <path
                        d="M 2.625 4 L 32 4 L 32 41 L 2.625 41 Z M 2.625 4 "
                        clip-rule="nonzero"
                      />
                    </clipPath>
                    <clipPath id="d384e1589d">
                      <path
                        d="M 2.625 0 L 32 0 L 32 7 L 2.625 7 Z M 2.625 0 "
                        clip-rule="nonzero"
                      />
                    </clipPath>
                    <clipPath id="5e6ef96cde">
                      <path
                        d="M 2.625 38 L 32 38 L 32 45 L 2.625 45 Z M 2.625 38 "
                        clip-rule="nonzero"
                      />
                    </clipPath>
                    <clipPath id="1397b892a3">
                      <path
                        d="M 38 14 L 42.375 14 L 42.375 21 L 38 21 Z M 38 14 "
                        clip-rule="nonzero"
                      />
                    </clipPath>
                  </defs>
                  .........

Removing this specific code made the list appear correctly. Here is the complete code:

import React from "react";
import TextField from "@mui/material/TextField";
import Autocomplete from "@mui/material/Autocomplete";
import { styled } from "@mui/system";
import { InputAdornment } from "@mui/material";

const GroupItems = styled("ul")({
  padding: 0,
  listStyleType: "none", // Remove default list styling
});

const RenderGroup = ({ top100Films }) => {
  const options = top100Films.map((option) => {
    const firstLetter = option.title[0].toUpperCase();
    return {
      firstLetter: /[0-9]/.test(firstLetter) ? "0-9" : firstLetter,
      ...option,
    };
  });

  return (
    <Autocomplete
      id="grouped-demo"
      options={options.sort(
        (a, b) => -b.firstLetter.localeCompare(a.firstLetter)
      )}
      groupBy={(option) => option.firstLetter}
      getOptionLabel={(option) => option.title}
      sx={{ width: 300 }}
      renderInput={(params) => (
        <TextField
          {...params}
          label="Campaigns"
          InputProps={{
            startAdornment: (/* Icon Code Removed */),
          }}
        />
      )}
      renderGroup={(params) => (
        <li key={params.key}>
          <GroupItems className="space-y-2">{params.children}</GroupItems>
        </li>
      )}
    />
  );
};

export default RenderGroup;

Answer №1

The presence of SVG code could be the reason behind the disturbance in the rendering process of the dropdown list. In some cases, SVG elements can disrupt the operations of other components within a certain context.

To troubleshoot this issue, consider separating the SVG code from the dropdown and observe if the dropdown functions properly without it. You can then gradually reintegrate the SVG code to pinpoint whether it is the root cause of the problem.

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

Unexpected behavior from HTML5 number input field

Is there a way to prevent users from entering values outside the specified max and min attributes? The constraints work when using the arrows in the input field, but not when typing directly into it. Note: I am considering utilizing angularjs for this fun ...

The way images appear can vary between desktop and mobile devices

I am in the process of creating a photography website with a simple goal of displaying images down the page one after another. However, I am encountering issues with uniform display across various desktop and mobile platforms. The site appears perfect on i ...

Explore three stylish ways to showcase dynamic JavaScript content using CSS

Objective: For Value 1, the CSS class should be badge-primary For Value 2, the CSS class should be badge-secondary For all other values, use the CSS class badge-danger This functionality is implemented in the handleChange function. Issue: Current ...

How to implement loading an external script upon a page component being loaded in NextJS

I recently transferred an outdated website to Nextjs and I am having trouble getting the scripts to load consistently every time a page component is loaded. When navigating between pages using next/link component, the scripts only run the first time the ...

Implementation of the I18next library

I am currently integrating react-i18next into my application to implement a switch button for French and English languages. Unfortunately, I am facing some issues as the translation is not working properly. I suspect it's related to the JSON file reco ...

How come e.target.value always shows the most recent value?

Starting out in HTML and I have a question regarding input. Here is the HTML code I am working with: <input type="text" value="abc" onChange={(e) => { console.log(e.target.value); }}/> I am puzzled because even though the default v ...

Exploring the intricacies of using jquery text() with HTML Entities

I am having difficulty grasping the intricacies of the jquery text() function when used with HTML Entities. It appears that the text() function converts special HTML Entities back to regular characters. I am particularly uncertain about the behavior of thi ...

Issue encountered while incorporating a PHP file into Javascript code

I'm facing a particular issue where I have a PHP file that is supposed to provide me with a JSON object for display in my HTML file. Everything seems to be working fine as I am receiving an output that resembles a JSON object. Here's the PHP file ...

Modify the color or background color of a disabled Material UI checkbox

The disabled unchecked checkbox appears too subtle to me, and I would like to enhance it by giving it a grey background and changing the cursor style to not-allowed. I've been trying to implement these styles on the checkbox using the makeStyles, but ...

The table refuses to load

I've been troubleshooting this issue for the past two days. The array is visible in the console, but it refuses to show up on the table. I've tried multiple approaches, but none seem to work. I suspect that "tobodyHtml" is not defined properly, a ...

What is the best way to incorporate lottiefiles for a loading animation on a Next.js project's landing

Is there a way to incorporate the use of lottie in a Next.js project (App Structure) in order to load an animated logo seamlessly? I attempted to include "use client" without success, and also tried importing Lottie from react-lottie as a dynamic import. ...

What is the best way to combine two buttons into a single button?

I have a dilemma with merging two buttons into one. <div className="mt-8 mb-16"> <button onClick={handlePurchase} type="button" // disabled='{this[id] <= 10}' className=&qu ...

Issue with AppBar not adhering to defined theme color in material-ui

I have utilized a theme created from the following site: My requirement is to have the primary color as RED and the secondary color as BLUE. Additionally, I would like the AppBar to have a shade of grey. The preview showcases the AppBar in the desired col ...

Show an HTML image encoded in base64 from its origin

Is there a way to embed a base64 image in HTML without having to paste the entire code directly into the file? I'm looking for a more efficient method. For example: <div> <p>Image sourced from an online repository</p> <img src=" ...

obtain the text content from HTML response in Node.js

In my current situation, I am facing a challenge in extracting the values from the given HTML text and storing them in separate variables. I have experimented with Cheerio library, but unfortunately, it did not yield the desired results. The provided HTML ...

Having an issue with Jquery selector where the text does not match

HTML Code <select id="myDropdown"> <option selected="selected" value="0">default</option> <option value="1">bananas</option> <option value="2">pears</option> </select> Javascript Function setDr ...

Unable to alter the pagination's selected page color to grey with material UI pagination components

Currently, I am implementing pagination using material UI. While I have successfully changed the page color to white, I am facing difficulty in changing the selected page color to grey. This issue arises because the background color is dark. import React, ...

What steps should I take to ensure that clicking this button triggers the API request and returns the data in JSON format?

I'm attempting to have the button with id 'testp' return an api request in json format, however it seems to not be functioning properly. You can find the HTML code link here: https://github.com/atullu1234/REST-API-Developer-1/blob/main/js-bu ...

Using jQuery to create clickable URLs within a rollover div

I am looking to have the div appear on a mouse over effect in the following code. Is there a way for me to input a url based on the data that is passed to it? Anchorage: ["Anchorage", "(555)555-5555"], (This represents the data being posted) AtlanticCit ...

The issue with jspdf is that it is failing to generate PDF documents of

I'm currently developing a resume builder app using ReactJS. One of the functionalities I'm working on is enabling users to download their resumes as PDFs. However, I've encountered an issue with the generated PDFs when using jsPDF. The down ...