Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI Auto Complete Rotate icon on expand or collapse

I want to rotate auto complete icon of material UI when auto complete component is expanded. enter image description here

This is the demo of Auto complete: https://codesandbox.io/s/0xx573qrln

Any help is greatly appreciated.

like image 843
Yasin Avatar asked Nov 29 '18 11:11

Yasin


1 Answers

You can make use of the components.DropdownIndicator prop of the react-select. The current state of the component can be accessed through selectProps prop of the component.

I ran into the same challenge, and this is how I did:

// Select.js

const styles = theme => ({
  dropdown: {
    transition: theme.transitions.create(["transform"], {
      duration: theme.transitions.duration.short
    })
  },
  dropdownOpen: {
    transform: "rotate(-180deg)"
  },
  dropdownClosed: {
    transform: "rotate(0)"
  }
})

function DropdownIndicator(props) {
  return (
    <KeyboardArrowDown
      className={[
        props.selectProps.classes.dropdown,
        props.selectProps.menuIsOpen
          ? props.selectProps.classes.dropdownOpen
          : props.selectProps.classes.dropdownClosed
      ]}
    />
  );
}

const components = { DropdownIndicator };

export function Select(props) {
  return <Select componenets={components} {...props} />
}

Hope you were able to solve the challenge yourself.

Demo (forked from above link): https://codesandbox.io/s/material-demo-b9frk

like image 107
Arghyadeb Avatar answered Sep 17 '22 12:09

Arghyadeb