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.

Formik setFieldValue right-aligns Select option when selected

See original GitHub issue

It seems that Formik.setFieldValue imperatively simulates typing in a value into the <input type="text" /> that’s rendered by the Select, which causes the text to be right-aligned.

Expected Behavior

Selected option inside the Select box should be left-aligned after selected

Actual Behavior

Selected option inside the Select box is right-aligned after selected

URL, screen shot, or Codepen exhibiting the issue

Code sandbox for repro: https://codesandbox.io/s/grommet-issue-4087-text-right-aligned-in-select-after-selecting-option-55oxz?file=/src/App.js

grommet-select-issue

Steps to Reproduce

  1. Create a custom handler that uses Formik.setFieldValue and pass it to the onChange prop of a Select component:
  const onChange = (event: GrommetSelectEvent<typeof options[number]>) => {
    const value = event.value?.id || form.initialValues[field.name];
    form.setFieldValue(field.name, value);
  };

Documentation on Formik.setFieldValue here: https://jaredpalmer.com/formik/docs/api/formik#setfieldvalue-field-string-value-any-shouldvalidate-boolean--void

  1. Pass these options to the same Select component: ['option 1', 'option 2', 'option 3', 'extra super long name that needs to be truncated inside the select box']
  2. In the UI, click the ‘extra super long name that needs to be truncated inside the select box’ option
  3. Verify that the selected text inside the Select box is right-aligned (see GIF above)

Your Environment

  • Grommet version: “grommet”: “^2.7.7”
  • Browser Name and version: Chrome for Mac Version 81.0.4044.138 (Official Build) (64-bit)
  • Operating System and version (desktop or mobile): macOS Catalina v10.15.4

Also reproducible in Edge, Safari, and Firefox.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jcfilbencommented, Sep 14, 2020

Sep-14-2020 10-44-01

It is still left-aligned for me even after selecting option 1 and then selecting the long-text option

1reaction
ShimiSuncommented, Jun 1, 2020

Can you please isolate the problem reliably on a newer version of grommet, and send us a codesandbox with the markup to explore the problem. it will have a quicker turnaround if we’ll know how you are using the component within Formik.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with select Field in Formik when onChange option ...
I think that you are not understanding how Formik and this Field component work. Formik is using its own internal state to handle...
Read more >
setfieldvalue formik | The AI Search Engine You Control
setFieldValue imperatively simulates typing in a value into the <input type="text" /> that's rendered by the Select , which causes the text to...
Read more >
REACT: react-select with Formik for Single and Multi Selections
react-select-> Costum Component file: MultiSelect.js ... setFieldValue( field.name, option ? (option).map((item) ... for Single Selection.
Read more >
Falcon Sandbox v8.31 © Hybrid Analysis
Formik,{initialValues:e,validationSchema:this. ... setFieldValue(_. ... jurisdiction selected");const{effectiveDate:t,endDate:a,formatValidationType:o ...
Read more >
Formik Select Example - CodeSandbox
Formik Select Example. 0. Embed Fork Create Sandbox Sign in. Sandbox Info. Formik Select Example. An example form built with Formik and React....
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