Skip to content

Commit fe7de4b

Browse files
committed
fix(colorinput): focus indication on MacOS and iOS
1 parent 7cf0224 commit fe7de4b

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

src/components/ColorInput/ColorInput.js

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import React from 'react';
22
import propTypes from 'prop-types';
33

44
import styled, { css } from 'styled-components';
5-
import { focusOutline } from '../common';
65
import useControlledOrUncontrolled from '../common/hooks/useControlledOrUncontrolled';
7-
import Button from '../Button/Button';
8-
import Bar from '../Bar/Bar';
6+
import { focusOutline } from '../common';
7+
import { StyledButton } from '../Button/Button';
8+
import Divider from '../Divider/Divider';
9+
10+
const Trigger = styled(StyledButton)`
11+
padding-left: 8px;
12+
`;
913

10-
const StyledBar = styled(Bar)`
11-
height: 23px;
14+
const StyledDivider = styled(Divider)`
15+
height: 21px;
1216
position: relative;
1317
top: 0;
1418
`;
@@ -27,10 +31,10 @@ export const StyledColorInput = styled.input`
2731
// TODO replace with SVG icon
2832
const ColorPreview = styled.div`
2933
box-sizing: border-box;
30-
height: 21px;
34+
height: 19px;
3135
display: inline-block;
3236
width: 35px;
33-
margin-right: 7px;
37+
margin-right: 5px;
3438
3539
background: ${({ color }) => color};
3640
@@ -45,6 +49,16 @@ const ColorPreview = styled.div`
4549
: css`
4650
border: 2px solid ${({ theme }) => theme.text};
4751
`}
52+
${StyledColorInput}:focus:not(:active) + &:after {
53+
content: '';
54+
position: absolute;
55+
left: 0;
56+
top: 0;
57+
width: 100%;
58+
height: 100%;
59+
${focusOutline}
60+
outline-offset: -8px;
61+
}
4862
`;
4963

5064
const ChevronIcon = styled.span`
@@ -75,9 +89,6 @@ const ChevronIcon = styled.span`
7589
width: 16px;
7690
height: 19px;
7791
}
78-
${StyledColorInput}:focus + &:after {
79-
${focusOutline}
80-
}
8192
`;
8293

8394
// TODO make sure all aria and role attributes are in place
@@ -105,14 +116,15 @@ const ColorInput = React.forwardRef(function ColorInput(props, ref) {
105116
};
106117

107118
return (
108-
// we only need button styles, so we display it as a div and reset type attribute
109-
<Button isDisabled={disabled} as='div' type={null} variant={variant}>
110-
<ColorPreview
111-
color={valueDerived}
112-
isDisabled={disabled}
113-
role='presentation'
114-
/>
115-
{variant === 'default' && <StyledBar />}
119+
// we only need button styles, so we display
120+
// it as a div and reset type attribute
121+
<Trigger
122+
isDisabled={disabled}
123+
as='div'
124+
type={null}
125+
variant={variant}
126+
size='md'
127+
>
116128
<StyledColorInput
117129
onChange={handleChange}
118130
readOnly={disabled}
@@ -122,8 +134,14 @@ const ColorInput = React.forwardRef(function ColorInput(props, ref) {
122134
ref={ref}
123135
{...otherProps}
124136
/>
137+
<ColorPreview
138+
color={valueDerived}
139+
isDisabled={disabled}
140+
role='presentation'
141+
/>
142+
{variant === 'default' && <StyledDivider vertical />}
125143
<ChevronIcon isDisabled={disabled} variant={variant} />
126-
</Button>
144+
</Trigger>
127145
);
128146
});
129147

0 commit comments

Comments
 (0)