question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select does not render label JSX in selected value

See original GitHub issue

Since version 1.5.0, Grommet’s Select dropdown component can render rich JSX, as long as the JSX is passed into an option’s label. For example, an option authored like this will render as a rich image in the select dropdown:

const options = [
  { label: <img src="http://i.imgur.com/iZS0F7D.jpg" />, value: 2}
  // .. more options ...
];

However, Grommet’s Select component does not support rendering the currently selected value’s label as JSX in dropdown (non-inline) mode. The component only supports strings, which creates a mismatch of expectations.

Instead, the JSX renders as [object Object] upon selection.


Expected Behavior

Grommet Select value should be able to render JSX labels as the selected value, as rich labels are supported on the dropdown options.

Actual Behavior

Grommet renders the selected value as a string, resulting in a visual [object Object] when the option.label is JSX.

URL, screen shot, or Codepen exhibiting the issue

https://codepen.io/drewlustro/pen/zzeyxW

Steps to Reproduce

  1. Create Grommet Select
  2. Provide rich JSX as the label in each option of the form { label: <span>somejsx</span>, value: 100}
  3. Activate the dropdown and choose a rich JSX option. Upon selection, the active value renders as a string [object Object] instead of JSX.

Your Environment

  • Grommet version: 1.5.0
  • Browser Name and version: Chrome 59.0.3071
  • Operating System and version (desktop or mobile): macOS 10.12.5 / desktop

In Action GIF

screen recording 2017-07-13 at 02 36 pm

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
alansouzaticommented, Jul 13, 2017

Yeah this is a limitation of the Select component as of now. The underlying component behind the selected value is an input which does not allow anything but text. I will keep this open and evaluate other solutions for Grommet 2.0. Thanks for raising this issue.

1reaction
florianbepunktcommented, Nov 10, 2017

@drewlustro Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-select does not show the selected value in the field
This is an alternative solution that i used. Demo: https://codesandbox.io/s/github/mkaya95/React-Select_Set_Value_Example import React, { useState } from ...
Read more >
How to Get Selected Value from a Mapped Select Input in React
To fetch the selected value from the select element, you can use the onChange event handler prop. Just like the input or textarea...
Read more >
Advanced - React Select
A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete and ajax support.
Read more >
Select - Ant Design
Select component to select value from options. ... Custom selection render. Specify the prop name of Option which will be rendered in select...
Read more >
Select API - Material UI - MUI
Name Type Default autoWidth bool false children node classes object
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found