Positioning of the dropdown in Material UI Autocomplete

Can the Material UI Autocomplete be customized easily to position the Popper dropdown relative to the text cursor, similar to the VS Code Intellisense dropdown? The input field is a multiline Textfield component.

The code snippet below demonstrates:

import React from "react";
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
import TextField from "@material-ui/core/TextField";
import Autocomplete from "@material-ui/lab/Autocomplete";
import Chip from '@material-ui/core/Chip';
import { Popper } from "@material-ui/core";

const targetingOptions = [
  { label: "(", type: "operator" },
  { label: ")", type: "operator" },
  { label: "OR", type: "operator" },
  { label: "AND", type: "operator" },
  { label: "Test Option 1", type: "option" },
  { label: "Test Option 2", type: "option" },
];

const useStyles = makeStyles((theme: Theme) =>
  createStyles({
    root: {
      '& .MuiAutocomplete-inputRoot': {
        alignItems: 'start'
      }
    },
  }),
);

export default () => {
  const classes = useStyles();

  const CustomPopper = function (props) {
    return <Popper {...props} style={{ width: 250, position: 'relative' }} />;
  };
  
  return (
    <div>
        <Autocomplete
        className={classes.root}
        multiple
        id="tags-filled"
        options={targetingOptions.map((option) => option.label)}
        freeSolo
        disableClearable
        PopperComponent={CustomPopper}
        renderTags={(value: string[], getTagProps) =>
          value.map((option: string, index: number) => (
            <Chip variant="outlined" label={option} {...getTagProps({ index })} />
          ))
        }
        renderInput={(params) => (
          <TextField {...params} variant="outlined" multiline={true} rows={20} />
        )}
      />
    </div>
  );
};

Answer №1

To enhance Autocomplete functionality in material ui, utilize the PopperComponent attribute to craft a personalized popper with the desired placement setting.

Refer to this link for more information: https://github.com/mui-org/material-ui/issues/19376

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

retrieve the value of the Firebase object's name property using ng-repeat

I am searching for a way to utilize a Firebase Object name as a parameter for the ui-router within an ng-repeat. It is important to note that fetching the favorite property as a Firebase array is not feasible. STRUCTURE OF THE OBJECT: https://i.sstatic. ...

Modify the CSS color attribute interactively by clicking

I have a function that can generate random colors. I would like to utilize this function along with jQuery's toggleClass feature to change the color of a table cell when clicked, and revert it back to its original color if clicked again. Here is the ...

The amazing property of AngularJS - Scope

I have saved this HTML code in a file. Here is the HTML : <!-- checkbox 1 --> <input type="checkbox" name="checkbox1" id="checkbox-group1" ng-model="checkbox1" value="group1"> <input type="checkbox" name="checkbox1" id="checkbox-group2" ng ...

Using Drag and Drop feature with Nightwatch and Selenium is not functional

While conducting a system test using nightwatch and selenium, I encountered an issue with dragging and dropping elements that are implemented with Knockout-draggable. Manually, the drag and drop functionality works perfectly. Below is the code snippet from ...

Steps to display a designated page in a MERN application exclusively for authenticated users

Upon logging in, I want to display the about us page with user information. If the user is not logged in, they should be redirected to the login page. However, even after logging in, I am still being redirected to the login page when trying to visit the ab ...

The NGX countdown timer is experiencing a discrepancy when the 'leftTime' parameter exceeds 24 hours, causing it to not count down accurately

When the leftTime configuration exceeds 864000, the timer does not start from a value greater than 24 hours. <countdown [config]="{leftTime: `864000`}"></countdown> For example: 1. When leftTime is set to `864000`, the Timer counts down from ...

Make the Material UI React TableCell adjust its width to fit the content dynamically

The code provided here is similar to the basic table layout from Material UI. The only modification made is in the content of the first row and second column. A Grid element has been incorporated within it, and additional columns have been added to create ...

Utilizing a (helper) function within Redux

I am currently using react-native-router-flux along with react-redux and I believe this is the right place to ask my question. Please correct me if I'm mistaken. Within my application, I have an ActivityModal Container which I use to display a modal ...

What is the best way to execute smooth drags or mobile swipes? Time Picker Rect Next Js 13 App Dir

After realizing that existing UI libraries lacked a time picker component where users could swipe up or down to select the hour, minutes, or PM/AM, I decided to create my own. My goal was to allow users to easily choose their desired time without having to ...

When tapping on grid items in the Safari browser using React Material-UI, they mysteriously switch positions

I've encountered an issue with grid Items in my React MATERIAL-UI project, specifically in the Safari browser. The problem does not occur in Chrome or Firefox. Within the grid, there are checkboxes that move from one place to another when clicked, a ...

What is the best way to modify the height of a div before fetching an image using Ajax, and then revert it back to its original height once the image has been

Using a form and Ajax, I'm dynamically pulling an image to replace another image in the .results div. Initially, when the image was removed and loaded, the page jumped up and down, so I tried adding a style attribute to set the div height and then rem ...

Limit the ability to zoom in a webview application

I am facing an issue with my Android WebView app that is designed to load a specific URL and display it along with its links within the app. Despite setting the webpage size to 720px x 1280px using CSS to fit the screen of a Galaxy S3, I am encountering di ...

Discord bot in Node.js, Remove old embed message upon receiving a slash command

My bot is programmed to send an embed message whenever it receives a /xyz command, and the code looks something like this: client.on("interactionCreate", async (interaction) => { if (!interaction.isCommand()) return; const ...

JS Code: Develop a function that generates a distribution analysis of an array

I have been working on a function that calculates the frequency distribution of an array. The aim is to output an object in which the keys represent the unique elements and the values show how frequently those elements appear. Here's the code I' ...

Unable to function properly for dividing sections

I am attempting to create a number field (.item_adults) that will multiply itself and display the value in a class called "item_price". Here is what I have created so far: <div class="bookSection"> <input class="item_adults" name="adults" type= ...

Node.js consecutive API requests failing to run

I am currently working on a project for one of my courses that requires chaining multiple API calls together. The issue I'm facing is that while the first API call function successfully executes and displays in the terminal, everything after it does n ...

issues related to implementing search functionality with react-redux

Just starting out with my first react-redux project which is a list of courses, but I have hit a roadblock with redux. I am trying to implement a search functionality based on this answer, and while I can see the action in redux-devtools, it's not ref ...

Reorganizing Objects in an Array Using NodeJS

Having the following dataset - an array of objects consisting of sender IDs and messages [ { "sender": "1000000000", "message": message 1" }, { "sender": "1000000000&quo ...

Image-switching button

I'm new to JavaScript and struggling with my first code. I've been staring at it for two days now, but can't figure out what's wrong. The goal is to create an HTML page where the user can change an image by clicking on a button, and th ...

Error message: When using the Three.JS STL Loader, an Uncaught TypeError occurs because the property 'scale' is being called on an undefined value

I am currently loading five elements using the STL Loader in order to create a table. My goal is to use dat.gui to adjust the scale of Tabletop.STL. Here is the code snippet: <!DOCTYPE html> <html lang="en> <head> <title& ...