Formik setFieldValue right-aligns Select option when selected
See original GitHub issueIt 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
Steps to Reproduce
- Create a custom handler that uses
Formik.setFieldValue
and pass it to theonChange
prop of aSelect
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
- 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']
- In the UI, click the ‘extra super long name that needs to be truncated inside the select box’ option
- 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:
- Created 3 years ago
- Comments:11 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It is still left-aligned for me even after selecting option 1 and then selecting the long-text option
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.