#reactjs #styled-components
#reactjs #стилизованные компоненты #styled-components
Вопрос:
У меня есть такая структура HTML:
<SearchBarContainer>
<i class="fa fa-search" aria-hidden="true" style={{ marginRight: "5px" }} />
<SearchBarText>What</SearchBarText>
<SearchBar type="text" name="" />
<SearchBarRightIcon>
<FaCity />
</SearchBarRightIcon>
</SearchBarContainer>
И это мой styled-components
:
export const SearchBarContainer = styled.div`
height: 10px;
background-color: #fff;
border-radius: 0.5rem;
display: flex;
align-items: center;
padding: 20px;
margin-left: 10px;
padding: .75rem 1rem;
font-family: 'Roboto',sans-serif;
border: 1px solid #949494 !important;
`;
export const SearchBarRightIcon = styled.div`
display:block;
color: red;
padding-left: 10px;
`;
export const SearchBar = styled.input`
flex: 1;
border: none;
outline: none;
font-size: 18px;
padding-left: 10px;
height: 21px;
amp;:focus{
background: pink;
// Let's remove the icon which is in the righ
${SearchBarContainer} {
background: blue !important;
box-shadow: 0 1rem 3rem rgba(0,0,0,.175)!important;
}
${SearchBarRightIcon} {
display: none;
}
}
`;
И, как вы можете видеть, у меня есть amp;:focus
атрибут, который изменяет только фон самого элемента, но он не работает ни для SearchBarRightIcon
, ни для SearchBarContainer
. Что не так? Я создал много атрибутов active и hover, которые изменяют родительские элементы, но я впервые имею дело с фокусом, что не так? Как я могу изменить SearchBarContainer
и SearchBarRightIcon
когда focus
срабатывает действие?