Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

227
Vistas
How to make some part of select list text bold and some normal font in React

I have to create a select list to show some product in a select. The list should show product name but there should be a count in bold text like this:
please see this image to understand the question

What I have tried is I am creating an array of the products and pushing my product in it along with product and count like this:

productInformation.push(currentProdName + " (" + cnt + " Product" + ")");

After that I am mapping it to json and binding it to select list like this:

var jsonProducts = productInformation.map(function (key, value) {
   return { value: key, label: key }
});


<Select  id="productName" name="productName" options={jsonProducts}  
   onChange={onSelectChange}  
   placeholder={"All Products ("+supplierProducts.length + ")"} 
   ref={productInputRef}  
   styles={{menu: provided => ({ ...provided, zIndex: 9999 }) }} />  

       

But by doing it this way, I am getting result like this: please see what currently i am achiving

How can I make count and product text bold in this?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

As you are mapping jsonProducts from productInformation array i would suggest

  let content = (<div >{ProductName}<b> {" (" + Count+ " Product" + ") "}</b></div>);
productInformation.push(content);

now map it as it is

var jsonProducts = productInformation.map(function (key, value) {
   return { value: key, label: key }
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

I am slightly out of my expertise area here on MUI and React but something like: (note I did not have access to your original JSON/JavaScript object for the p.count here but perhaps you can work with this:

<CustomSelect>
  <StyledOption value={}>"All Products ({supplierProducts.length})"</StyledOption>
  {jsonProducts.map((p) => (
  <StyledOption value={c.value}>
    {p.label} <span style="font-weight:bold;">({p.count}) Products</span>
  </StyledOption>
  ))}
</CustomSelect>

Reference: https://mui.com/components/selects/

about 4 years ago · Juan Pablo Isaza Denunciar

0

Import the "MenuItem" from the Mui library and use it as you would any other tag.

But before you should clean certain parts of your code before

productInformation.push({currentProdName, cnt});

var jsonProducts = productInformation.map(function (prod) {
   return <MenuItem value={prod.currentProdName+ " (" + prod.cnt + " Product" + ")"}>{prod.currentProdName}<b>&nbsp;{ "(" + prod.cnt + " Product" + ")"}</b></MenuItem>
});


<Select  id="productName" name="productName" onChange={onSelectChange}  
   placeholder={"All Products ("+supplierProducts.length + ")"} 
   ref={productInputRef}  
   styles={{menu: provided => ({ ...provided, zIndex: 9999 }) }} >

  {jsonProducts}
</Select>

As you can see you'll have to fill the data in MenuItem and then add the object to the Select.
I changed how the information is pushed into the productInformation array (for better control)
Note: I removed jsonProducts from options and into the inside of Select tag.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda