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
Changes from 1 commit
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
Next Next commit
fixes broken focus outline on the Select component
  • Loading branch information
mperrotti committed Jul 18, 2022
commit 2fa1137cf0eb5a2ba187e189fdb426b272a96b5b
11 changes: 10 additions & 1 deletion src/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import React from 'react'
import styled from 'styled-components'
import {get} from './constants'
import TextInputWrapper, {StyledWrapperProps} from './_TextInputWrapper'

export type SelectProps = Omit<
Omit<React.ComponentPropsWithoutRef<'select'>, 'size'> & Omit<StyledWrapperProps, 'variant'>,
'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 +24,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 +59,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