Choose elements with unique identifiers other than those provided by the API

Seeking assistance with Material UI select element and naming dropdown. Have a few questions:

1: My API that populates the dropdown lacks good names. Is it possible to assign names like 'data 1, data 2, data 3...' to the options without manually editing the array in the API?

Currently, I have set it to '{option.label}' which comes from an array of objects. Is there a way to automatically set names like 'data 1, data 2, data 3...' without directly modifying the array (which could be quite extensive)?

2: Despite setting a background color, it doesn't seem to affect that particular section. Any insights on why this might be happening?

3: The input label name is positioned above the select field. How can I move it inside instead?

I have scoured Stack Overflow for answers without much luck, hence reaching out here with all three queries. Apologies for any language errors as English is not my native tongue.

Codesandbox: https://codesandbox.io/s/basicselect-material-demo-forked-bpu71w?file=/demo.js

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

Here's the code snippet for reference:

import * as React from "react";
import Box from "@mui/material/Box";
import InputLabel from "@mui/material/InputLabel";
import MenuItem from "@mui/material/MenuItem";
import FormControl from "@mui/material/FormControl";
import Select from "@mui/material/Select";
import "./Tama.css";

export default function BasicSelect() {
  const [dataa, setData] = React.useState("twny");

  const handleChange = (event) => {
    setData(event.target.value);
  };

  const data = [
    {
      value: "USD",
      label: "$"
    },
    {
      value: "EUR",
      label: "€"
    },
    {
      value: "BTC",
      label: "฿"
    },
    {
      value: "JPY",
      label: "¥"
    }
  ];

  return (
    <Box sx={{ m: 1 }}>
      <FormControl fullWidth>
        <InputLabel id="demo-simple-select-label">Age</InputLabel>
        <Select value={dataa} onChange={handleChange} className="ok">
          {data.map((option) => (
            <MenuItem
              className="menuItem"
              onClick={() => console.log("Chosen: ", option.label)}
              key={option.value}
              value={option.value}
            >
              {option.label}
              <button
                className="menuItem__button"
                onClick={() => console.log("Clicked: ", option)}
              >
                Edit
              </button>
            </MenuItem>
          ))}
        </Select>
      </FormControl>
    </Box>
  );
}
.menuItem {
  border: 1px solid gray;
  background-color: #1e2328;
  color: red;
}

.menuItem__button {
  margin-left: 90%;
}

#demo-simple-select-label {
  color: red;
}

.ok {
  background-color: #1e2328;
  color: white;
}

Answer №1

1- Updating the list value directly from your API may not be the best approach.

2- To resolve background issues, try adding the following CSS:

.MuiList-root {
  border: 1px solid gray;
  background-color: #1e2328;
  color: red;
}

3- If you want to hide the label in an input field, use variant="outline".

<InputLabel id="demo-simple-select-label" variant="outline">Age</InputLabel>

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

Learn how to extract an entire table from a website using Kimono Labs, rather than just the first ten rows

Currently, I am utilizing Kimono labs to generate an API for scraping data from the table on this specific website. However, the website only displays the initial 10 rows of the table by default, limiting my API output to just 10 rows. Is there a method to ...

Is there a way to distinguish between automated bots and human users who are visiting my website?

Is there a way to detect if a bot is navigating my website? My website requires users to submit a form in order to access the next page. To speed up the page load time, I perform additional background database queries when a user submits the form. Howev ...

What impact does incorporating a server directory have on the build script of create-react-app?

Currently, I am working with create-react-app and have decided to incorporate an express backend. I am curious about how including this server directory in my application will impact CRA's build script when it comes time to deploy the app. Will the se ...

Develop a customized interface for exporting styled components

I am struggling to figure out how to export an interface that includes both the built-in Styled Components props (such as as) and my custom properties. Scenario I have created a styled component named CustomTypography which allows for adding typographic s ...

ReactJS and Webpack: Troubleshooting image display issues

I am having trouble loading a background image in my component. Despite using require('imagepath') to load the image, it gets changed to url('imagepath') during build. However, when I try to load it within my styles that are being added ...

Ways to properly update a state variable when using onClick within a functional component

I'm having an issue with my tabs that are supposed to display different products and filters when clicked. Currently, I have to click each tab twice before the 'options' list updates with the correct filters. I know that calling setOptions w ...

What is the process for creating a local repository for Node.js npm?

When it comes to the building process in node js, there are a few goals that need to be called: Begin by calling npm install, which creates a folder called node_modules and places all dependencies from package.json into it. [for UI development] Execute a ...

Owner executes the Snowflake Store Procedure

Attempting to create a stored procedure with 'execute as owner' in order to return a list of tables. The SP was successfully created, however calling it results in an error. create database garbage; CREATE OR REPLACE procedure garbage.public.san ...

Angular Material: Enhanced search input with a universal clear button

After searching for a cross-browser search control with a clear button similar to HTML5, I found the solution rendered by Chrome: <input type="search> The code that gave me the most relevant results can be found here. I used the standard sample w ...

Can the parcel bundler dist folder be customized for decoration?

After compiling code with parcel using the command parcel src/index.html, all files are generated inside the dist folder. However, I am looking for a more organized way to manage these files once my website is complete. Ideally, I want separate folders suc ...

An HTML form containing various input fields organized as a JSON string

I need to pass two parameters, param1 and param2, to a servlet. Param1 should be in JSON format, while param2 is a regular input value. param1 = {"id":"userid","name":"username","status":"userstatus"} param2 = add How can I accomplish this using the HTM ...

Is it possible to display the aggregation result (sum) in the table header using MUI Data Grid Aggregation?

I am in the process of designing a dashboard using MUI library for React. My main question pertains to Data aggregation, with resources found in the official documentation here: https://mui.com/x/react-data-grid/aggregation/ Specifically, I am wondering i ...

Enhancing Your Model with Additional Details using Angular Formly

I have been utilizing Angular Formly to display forms generated from the JSON response received from services. However, I have a few inquiries. Is it feasible to retrieve data in a field (templateOptions.label, for instance) to include in the model? ...

How can we ensure that the load more button disappears at the appropriate moment in this Vue 3 application?

I have been developing a news application with Vue 3 and the News API. I am currently implementing a feature for loading more articles on the page. Initially, there are 24 articles displayed, and if there are more articles available than the current numbe ...

Accessing data points in jQuery

Here is a sample code I'm working with : <script type="text/javascript"> var currentPicture;//default picture var picEL;//the image viewer element jQuery("#backImageShower").hover( function(i) { picEL = j ...

Automatically insert a new row into the table when the last row field is clicked for the first time

I am looking to create a table that will automatically add a new row when a user clicks on the last row in the table. The row will consist of 2 text boxes, and the goal is to create a list that can grow dynamically, with the option to delete rows as well ( ...

Google API integration in Chrome Extension Manifest

I'm seeking advice on how to modify my chrome manifest for an extension in order to enable communication between Google API servers and the application. The application functions properly when accessed directly (not as an extension). However, when lo ...

What is the best way to activate a JQ function with my submit button?

Is there a way to trigger a JQ function when clicking the submit button in a form? I managed to make Dreamweaver initiate an entire JS file, but not a particular function. ...

Transform a String into an Array object

There is a string that resembles the following pattern: var stringArray = "[[1,2,3,4],[5,6,7,8]]" The objective is to use Javascript to convert it to the following format: var actualArray = [[1,2,3,4],[5,6,7,8]] What would be the method to accomplish ...

React is throwing a parsing error due to the incorrect use of braces. Remember, JSX elements must be wrapped in an enclosing tag. If you were trying to include multiple elements without a parent tag, you can use a JSX fragment

Having recently started working with React, I came across this code snippet return ( <div> dropdown ? (<li className='goal-list-item' onClick={() => setDropdown(!dropdown)}>{goal.name}</li>) : ...