Can you assist me with styling? I am having an issue where only one of my buttons can turn blue (focus) at a time, instead of multiple buttons turning blue simultaneously.
This is how my components are structured...
import { Container, Content } from './styles';
function PressedButton({ children, ...rest }) {
const [pressed, setPressed] = useState(false);
return (
<Container>
<Content
type="button" {...rest}
pressed={pressed}
onFocus={() => setPressed(!pressed)}
>
{children}
</Content>
</Container>
);
}
The styles for the PressedButton component are as follows...
import styled from 'styled-components';
(...)
export const Content = styled.button`
(...)
//props
background: ${({ pressed }) => pressed ? `linear-gradient(#449fd8, #1b699a)` : '#2a2a2a'};
color: ${({ pressed }) => pressed ? '#fff' : '#7d7d7d'};
Here is a visual representation of my problem
In my parent component, the rendering looks like this...
tags.forEach((tag) => {
let output = <PressedButton onClick={() => handleTag(tag)}>{tag}</PressedButton>