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

146
Views
How to change other components' property with styled-components?

I am using styled-components and I am trying to change the height of Top to 300px when I focus on my Input.

I was tried something like this but not working:

&:focus ${Top} {
  height: 500px;
}

Dom Structure:

<Top>
    <Avatar
            src="./assets/person/1.jpeg"
            alt=""
            sx={{ width: "50px", height: "50px" }}
      />
      <Input placeholder="What's in your mind?" />
</Top>

My code:

export const Top = styled.div`
  display: flex;
  align-items: flex-start;
  height: 150px;
`;

export const Input = styled.textarea`
  flex: 1;
  height: 100%;
  resize: none;
  border: none;
  outline: none;
  font-size: 16px;
  padding: 10px;

  &:focus ${Top} {
    height: 500px;
  }
`;

How do I change other components' prop with styled-components?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use ~ selector:

export const Top = styled.div`
  display: flex;
  align-items: flex-start;
  height: 150px;
`;

export const Input = styled.textarea`
  flex: 1;
  height: 100%;
  resize: none;
  border: none;
  outline: none;
  font-size: 16px;
  padding: 10px;

  &:focus ~ ${Top} {
    height: 500px;
  }
`;

What's your dom structure?

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!