Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken focus outline on the Select component #2173

Merged
merged 5 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/grumpy-rings-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Updates styles for the Select component so that the focus outline is even all the way around.
10 changes: 9 additions & 1 deletion src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ export type SelectProps = Omit<
'multiple' | 'hasLeadingVisual' | 'hasTrailingVisual' | 'as'
>

const arrowRightOffset = '4px'

const StyledSelect = styled.select`
appearance: none;
border-radius: inherit;
border: 0;
color: currentColor;
font-size: inherit;
Expand All @@ -20,8 +23,13 @@ const StyledSelect = styled.select`

background-color should be 'transparent', but Firefox uses the background-color on
<select> to determine the background color used for the dropdown menu.

2. Adds 1px margins to the <select> so the background color doesn't hide the focus outline created with an inset box-shadow.
*/
background-color: inherit;
margin-top: 1px;
margin-left: 1px;
margin-bottom: 1px;

/* 2. Prevents visible overlap of partially transparent background colors.

Expand Down Expand Up @@ -50,7 +58,7 @@ const ArrowIndicatorSVG: React.FC<{className?: string}> = ({className}) => (
const ArrowIndicator = styled(ArrowIndicatorSVG)`
pointer-events: none;
position: absolute;
right: 4px;
right: ${arrowRightOffset};
top: 50%;
transform: translateY(-50%);
`
Expand Down