Create a row in React JS that includes both a selection option and a button without using any CSS

My dilemma involves a basic form consisting of a select element and a button. What I want to accomplish is shifting the position of the form to the right directly after the select element https://i.sstatic.net/3gfkO.png

Below is the code snippet that I have:

 return (
<>
  <div>
    <Select
      {...props}
      mode="multiple"
      labelInValue
      showArrow
      options={scopes && scopes.map((scope) => ({ value: scope.scopeId, data: scope }))}
      loading={!scopes || scopes.notLoaded}
      onFocus={fetchData}
      placeholder={'Choose existing scopes'}
      notFoundContent={notFoundContent}
      onSearch={onSearch}
      onChange={handleChange}
      value={selectedScopes && selectedScopes.map((_) => ({ value: _.scopeId, data: _ }))}
    />
    <Button type="primary" disabled={isCreationVisible} onClick={() => showModal()}>
      Create
    </Button>
  </div>
  <ScopeCreationForm
    initialId={searchValue}
    visible={isCreationVisible}
    nameUniqValidator={nameUniqValidator}
    onCreate={handleCreate}
    onCancel={handleCancel}
  />
</>

The question here lies in how can I achieve this desired positioning without the need for a separate CSS file

Answer №1

Consider using the display: flex property:

<div style={{ display: 'flex'}}>
    <Select          
      ...
    />
    <Button           
      type="primary" disabled={isCreationVisible} onClick={() => showModal()}>
      Create
    </Button>
  </div>

Answer №2

To resolve this issue, consider utilizing the display: flex property in your CSS.

There are various methods to incorporate your CSS within a JS file. One straightforward approach is to include your styles inline, as suggested by others. You can attempt the following:

<>
  <div 
    style={{ display: 'flex', alignContent: 'center', justifyContent: 'center'}}
  >
    <Select
      {...props}
      mode="multiple"
      labelInValue
      showArrow
      options={scopes && scopes.map((scope) => ({ value: scope.scopeId, data: scope }))}
      loading={!scopes || scopes.notLoaded}
      onFocus={fetchData}
      placeholder={'Choose existing scopes'}
      notFoundContent={notFoundContent}
      onSearch={onSearch}
      onChange={handleChange}
      value={selectedScopes && selectedScopes.map((_) => ({ value: _.scopeId, data: _ }))}
    />
    <Button type="primary" disabled={isCreationVisible} onClick={() => showModal()}>
      Create
    </Button>
  </div>
  <ScopeCreationForm
    initialId={searchValue}
    visible={isCreationVisible}
    nameUniqValidator={nameUniqValidator}
    onCreate={handleCreate}
    onCancel={handleCancel}
  />
</>

Another method of incorporating CSS within JS files involves using tools like styled-components or implementing material-ui's makeStyles paradigm.

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

Accessing files from various directories within my project

I'm working on a project with 2 sources and I need to import a file from MyProject into nest-project-payment. Can you please guide me on how to do this? Here is the current file structure of my project: https://i.stack.imgur.com/KGKnp.png I attempt ...

Implementing a feature that loads older posts on a webpage as users scroll down

Spent hours trying to get my site to automatically load older posts on scroll down with no luck. Any assistance is greatly appreciated :) After researching, [this tutorial][1] seemed like the best solution so I followed it step by step and integrated ever ...

Xpath-Utilizing a variable within an XPATH expression is necessary

Currently, I am utilizing Selenium-webdriver and facing an issue while trying to select an element based on its "text" using xpath. Since the value is subject to change, I am utilizing a variable. I am looking for a solution to resolve this problem or an a ...

Switch out everything except for the initial one

Can all instances be replaced except for the first one? For example, 123.45.67..89.0 should turn into 123.4567890. Edit: Specifically seeking a regex solution. I am aware of how to achieve it through concatenation or using the index. ...

Concealing a Div on Click Outside of Child Div in ReactJS

I have a parent div with a child div in the center. I am trying to figure out how to close the parent div only when clicking outside of the child div. My current code is structured like this, using triggerParentUpdate to control whether the div should be d ...

The rendering with Three.js has finished successfully

I'm curious, is there a way to determine when the object has finished rendering? While I've seen a progress bar in one example, I'm seeking a straightforward and uncomplicated illustration. So far, I've searched through the loader I&apo ...

Polymer custom components and Polymer motion recognition techniques

Looking to implement a listener event on a Polymer custom element using Polymer-gestures. Here is a snippet of my code: - my-custom-element.html <link rel="import" href="../polymer/polymer.html"> <polymer-element name="my-custom-element" attri ...

Tips for retrieving data from multiple text boxes in a loop in React js and transmitting it to an API

I am in the process of developing a quiz application where I aim to create multiple question input fields based on the administrator's inputs. For example, if the admin provides 10 questions for the quiz, I will then generate a form within a loop fo ...

Styling a HTML div element with a header and footer, while also ensuring that the

My goal is to create a div that features a header with a unique background design. The content within the div should have a background consisting of a one-pixel repetition at y, or maybe something different? I also want a footer with its own distinctive ...

How can we automate the process of assigning the hash(#) in Angular?

Is it possible to automatically assign a unique hash(#) to elements inside an ngFor loop? <div *ngFor="let item of itemsArray; index as i"> <h3 #[item][i]> {{ item }} </h3> </div> I would like the outp ...

CSS containers not lining up correctly

Currently in the process of developing a web application, I am facing challenges with my CSS panels constantly shifting around unexpectedly. These panels feature an image with a 4:3 aspect ratio along with a description section. While they appear stable ...

Tips for selectively applying CSS to a single HTML file

I'm currently working on a website utilizing AngularJS and Plangular to develop a unique Soundcloud Player. This is how I incorporate my template: <body> <div id="container"> <div id="header" ng-controller="HeaderCtrl"><div ...

Best practices for assigning values to model field in EXT JS are as follows:

I'm facing an issue with a certain model structure: Ext.define('my.workspace.Area', { extend: 'Ext.data.Model', idProperty: 'id', fields: [ {name: 'id', type: 'string'}, {n ...

Checking for correct format of date in DD/MM/YYYY using javascript

My JavaScript code is not validating the date properly in my XHTML form. It keeps flagging every date as invalid. Can someone help me figure out what I'm missing? Any assistance would be greatly appreciated. Thank you! function validateForm(form) { ...

Executing multiple commands using Node.js TCP communication

I have established a connection to a serial device via the internet using an ethernet to serial device. The communication is facilitated through a small node.js application. The provided code retrieves the necessary information: var net = require('ne ...

Leverage the version attribute within package.json within one of its scripts

Is there a way to access the version attribute of my package.json file within one of its scripts? I want to include the version number in the name of the JS bundle, instead of using a hash as an identifier. This is what I currently have: "build-js": "bro ...

Gather data from various textboxes and combine them into a unified string with the help of JavaScript

I am currently facing a challenge where I need to extract the values from multiple textboxes and combine them into a single string. This string will then be sent to my PHP processing page for insertion into a database table. The textboxes mentioned above ...

Finding MongoDB data using an Express route and displaying it in a Jade template

Is there a way to retrieve data from MongoDB using an express route and display it in a jade template? Below is the code snippet of my express route (express version 2.5.8): app.get('/showData',function(req,res){ db.collection('comme ...

Ensure accuracy when converting to a float data type

My dilemma involves sending numerical values to a server using an AJAX call. For instance, numbers like 0.77, 100, and similar variations are being transmitted. However, upon reaching the server, the data is being interpreted differently - 0.77 as a double ...

What is the method for incorporating a link in an accordion header next to the toggle button with Bootstrap?

I'm attempting to enhance a link in the accordion-button so that only the arrow is clickable for collapsing. The CSS I added below makes the arrow clickable, but I am having trouble getting the link in the accordian-button to work. I want users to be ...