Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove outline from Material UI button using by breakpoint

I want to remove the outlined variant at the small medium and down breakpoint. To do this, I have tried to do the following:

const variantType = theme.breakpoints.down('md') ? '' : 'outlined';

<Button name="buyFood" variant={variantType} onClick={this.openFoodModal}>
  Buy
</Button>;

This does not do the job. I have tried researching and no one seemed to ask this question before. So here is the first of its kind. lol

like image 664
kenny335 Avatar asked Sep 11 '25 12:09

kenny335


1 Answers

You can do this by using the useTheme and the useMediaQuery hooks from Material UI.

import { Button, useTheme, useMediaQuery } from '@material-ui/core'

export default function App() {
  const theme = useTheme();
  const mediumDown = useMediaQuery(theme.breakpoints.down('md'));

  return (
    <div className="App">
      <Button name="buyFood" variant={mediumDown? 'text' : 'outlined' } onClick={this.openFoodModal}>
        Smart Suggest
      </Button>
    </div>
  );
} 

Edit Button variant controlled by media query

like image 198
Richard Hpa Avatar answered Sep 13 '25 01:09

Richard Hpa