Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
React MUI partially collapsible grid sections

I wanna make a scalable grid of items were items with showDefault: true always are shown at the top and then one can click arrow button to expand grid to also show the items with showDefault: false

Any way to make this?

interface IGridItem {
  id: string
  name: string
  showDefault: boolean
}

function MyGrid(){
  return (
    <>
      <IconButton onClick={}><ArrowIcon/></IconButton>
      <Box
        sx={{
          display: "grid",
          gridTemplateColumns: "repeat(auto-fill, minmax(187, 1fr))"
        }}
      >
        {items.filter(item => item.showDefault).map(item => <MyGridItem key={item.id} item={item}/>)}
        {items.filter(item => !item.showDefault).map(item => <MyGridItem key={item.id} item={item}/>)}
      </Box>
    </>
  )
}

function MyGridItem({item}: {item: IGridItem}){
  return (
    <Box>
      {item.name}
    </Box>
  )
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could conditionally render the items that you want, whether the non-default ones should be shown:

interface IGridItem {
  id: string
  name: string
  showDefault: boolean
}

function MyGrid(){
  const [showDefault, setShowDefault] = useState(false);

  const handleOnShowDefault = () => {
     setShowDefault(prev => !prev);
  }

  return (
    <>
      <IconButton onClick={handleOnShowDefault}><ArrowIcon/></IconButton>
      <Box
        sx={{
          display: "grid",
          gridTemplateColumns: "repeat(auto-fill, minmax(187, 1fr))"
        }}
      >
        {items.filter(item => item.showDefault).map(item =>
          <MyGridItem key={item.id} item={item}/>
        )}

        {showDefault && items.filter(item => !item.showDefault).map(item => 
             <MyGridItem key={item.id} item={item}/>
        )}
      </Box>
    </>
  )
}

function MyGridItem({item}: {item: IGridItem}){
  return (
    <Box>
      {item.name}
    </Box>
  )
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!