Skip to content

Commit 0f34f44

Browse files
committed
fix(button): indicate focus on Button
1 parent bfd978e commit 0f34f44

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/components/Button/Button.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
createBoxStyles,
1111
createFlatBoxStyles,
1212
createDisabledTextStyles,
13-
createHatchedBackground
13+
createHatchedBackground,
14+
focusOutline
1415
} from '../common';
1516
import { blockSizes, fontSizes, padding } from '../common/system';
1617

@@ -24,10 +25,20 @@ const commonButtonStyles = css`
2425
fullWidth ? '100%' : square ? blockSizes[size] : 'auto'};
2526
padding: ${({ square }) => (square ? 0 : `0 calc(${padding.sm} + 2px)`)};
2627
font-size: ${fontSizes.md};
28+
user-select: none;
2729
&:active {
2830
padding-top: ${({ isDisabled }) => !isDisabled && '2px'};
2931
}
3032
padding-top: ${({ active, isDisabled }) => active && !isDisabled && '2px'};
33+
&:after {
34+
content: '';
35+
position: absolute;
36+
display: block;
37+
top: 0;
38+
left: 0;
39+
height: 100%;
40+
width: 100%;
41+
}
3142
`;
3243

3344
export const StyledButton = styled.button`
@@ -46,12 +57,17 @@ export const StyledButton = styled.button`
4657
outline: 2px solid transparent;
4758
outline-offset: -4px;
4859
`}
60+
&:focus:after {
61+
${focusOutline}
62+
outline-offset: -6px;
63+
}
4964
`
5065
: variant === 'menu'
5166
? css`
5267
${createBoxStyles()};
5368
border: 2px solid transparent;
54-
&:hover {
69+
&:hover,
70+
&:focus {
5571
${!isDisabled && !active && createWellBorderStyles(false)}
5672
}
5773
&:active {
@@ -95,6 +111,13 @@ export const StyledButton = styled.button`
95111
&:active:before {
96112
${!isDisabled && createBorderStyles({ invert: true })}
97113
}
114+
&:focus:after {
115+
${focusOutline}
116+
outline-offset: -8px;
117+
}
118+
&:active:focus:after {
119+
top: ${active ? '0' : '1px'};
120+
}
98121
`}
99122
${commonButtonStyles}
100123
`;

0 commit comments

Comments
 (0)