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

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

Unlock the power of nested dynamic content creation with JavaScript

Every time I attempt to use getelementbyid on a dynamically loaded div, I receive null as the result. This occurs even after trying both window.onload = function () { and $(window).load(function() { index.html: <main > <div id="main-div"> ...

I am attempting to implement an Express static middleware as demonstrated in this book, but I am having trouble understanding the intended purpose of the example

I'm currently studying a chapter in this book that talks about Express, specifically concerning the use of express.static to serve files. However, I'm encountering an issue where the code catches an error when no file is found. I've created ...

"Exploring the versatility of NextJS with dynamic route parameters

Can NextJS be configured to handle dynamic routes that match both /country and /country/city, while excluding matches like /country/city/whatever_content_here? The goal is to display the same content for either of the specified routes, regardless of whethe ...

Tips for documenting curried functions using Js docs

I'm encountering issues while trying to use Js docs for generating static documentation of my project. When attempting to run the js doc command, I am faced with numerous parse errors specifically in areas where I have curried functions. Strangely, my ...

CSS DROP DOWN NAVIGATION MENU - Struggling to maintain hover effect on main menu item while navigating through sub-menu

I am facing a challenge with a CSS-only drop-down menu where the top main menu item loses its highlight when I move the cursor over the sub-menu items. You can view the menu in action here: . For example, if you hover over "Kids" and then move your cursor ...

issues stemming from the css of leaflets

This is my first time using leaflet and I am encountering a CSS issue. I'm not sure if there is another CSS file for leaflet, but whenever I try to adjust its position, it changes unexpectedly. I have a floating nav bar that should appear when scroll ...

Can you explain the process of retrieving API information from a component directory with Next.js?

In the components folder, I have created a reusable component that displays user details for those who log into the system in the header section. Currently, I am attempting to utilize getInitialProps with isomorphic-unfetch. static async getInitialProps( ...

Is it advantageous to employ several wrapper-divs inside section elements when working with HTML5 and CSS?

Back in the day, I learned how to create a website by enclosing all content below the body tag within a div with the class "wrapper." This approach made sense as it allowed for easy vertical and horizontal alignment of the entire content. Just yesterday, ...

Update a specific element within Angular framework

Just starting out with angular and facing a seemingly simple issue that I can't seem to solve despite trying various solutions found on SO. I have created a login component where upon submission, the user is redirected to their profile page. While I a ...

Mastering the art of writing protractor scenarios

In a hypothetical scenario where an Angular app consists of two pages - one for contacts (featuring a table with contacts and an "add new contact" button) and another for adding a new contact, the following steps can be outlined: Click on the "add" butto ...

Flickity remains in plain sight on desktop devices

I am trying to hide the flickity slider on desktop and larger devices. I have followed the instructions in the documentation, but for some reason, it's not working as expected. Here is how the div looks: <div class="w-full flex pl-4 pb-16 overflo ...

Arrange divs in a stack fashion

Currently, I have a table-styled three-column set of divs. I would like these columns to stack vertically on mobile devices. I think this can be achieved using the float method, but the titles and descriptions for each column are in separate rows (divs), ...

Ways to delete a header from the req object in Express

Can anyone help me understand how to remove a header from the req object in Express? I've heard that using res.disable("Header Name") can do this for the res object, but it doesn't seem to work for req.headers. ...

Exploring the nuances between Ruby on Rails and the responses from json and JavaScript ajax

I am interested in learning the most effective method for handling an ajax request. Would it be better to send json data and parse it on the client side (for instance using pure), or should I generate javascript at the server side and send back the respo ...

Calculating the sum in a VueJS pivot table

Currently, I am delving into VueJS and working on migrating a basic application from Laravel with the blade template engine. The backend remains unchanged, consisting of a straightforward RESTful API with 3 tables: Books, Places, and a pivot table named B ...

Ways to verify a correct email address using ReactJS

I'm currently working on a project using React.js and Next.js. I'm encountering an issue with handling the Axios response in Next.js as it's displaying "[object Object]" instead of the actual response data. How can I properly handle the resp ...

NextAuth encountered a CLIENT_FETCH_ERROR error while processing the session callback

Encountering issues while trying to set up nextauth v4. Keep getting this error: Client fetch error, Unexpected end of JSON input {error: {…}, path: 'session', message: 'JSON.parse: unexpected end of data at line 1 column 1 of the JSON d ...

What could be causing the image not to appear on the React app?

I'm currently working on a react website, and I'm facing an issue with the image display on the single product page. Despite trying to tweak both the react and CSS code, I haven't been able to resolve the problem. Below is my react file: im ...

Understanding special characters within a URL

Here is a URL example: postgres://someuser:pas#%w#@rd-some-db.cgosdsd8op.us-east-1.rds.amazonaws.com:5432 This URL is being parsed using the following code snippet: const url = require('url'); const { hostname: host, port, auth, path } = url.par ...

Exploring the intricacies of mapping an Array of Arrays

I'm currently tackling a data manipulation project that involves iterating through an array of arrays and generating a single string containing all possible combinations found within these arrays. For instance: const array = [ [{id: 1}, {id: 2}], ...