Skip to content

[dev-overlay] Expand clickable area for Select component in user preferences #80300

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

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from
Open
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, type HTMLProps } from 'react'
import React, { useState, type HTMLProps } from 'react'
import { css } from '../../../../../utils/css'
import EyeIcon from '../../../../icons/eye-icon'
import { STORAGE_KEY_POSITION, STORAGE_KEY_THEME } from '../../../../../shared'
Expand Down Expand Up @@ -237,14 +237,40 @@ export function UserPreferences({
function Select({
children,
prefix,
value,
...props
}: {
prefix?: React.ReactNode
} & Omit<React.HTMLProps<HTMLSelectElement>, 'prefix'>) {
value?: string | number
} & Omit<React.HTMLProps<HTMLSelectElement>, 'prefix' | 'value'>) {
let displayValue = ''
let longestText = ''

React.Children.forEach(children, (child) => {
if (
React.isValidElement<React.OptionHTMLAttributes<HTMLOptionElement>>(child)
) {
const childText = child.props.children as string
if (childText.length > longestText.length) {
longestText = childText
}
if (child.props.value === value) {
displayValue = childText
}
}
})

return (
<div className="select-button">
{prefix}
<select {...props}>{children}</select>
<div className="select-value-wrapper">
<span>{longestText}</span>
<span>{displayValue}</span>
</div>

<select value={value} {...props}>
{children}
</select>
<ChevronDownIcon />
</div>
)
Expand Down Expand Up @@ -328,12 +354,17 @@ export const DEV_TOOLS_INFO_USER_PREFERENCES_STYLES = css`
}

.select-button {
position: relative;
&:focus-within {
outline: var(--focus-ring);
}

select {
all: unset;
position: absolute;
inset: 0;
opacity: 0;
cursor: pointer;
}

option {
Expand All @@ -342,6 +373,17 @@ export const DEV_TOOLS_INFO_USER_PREFERENCES_STYLES = css`
}
}

.select-value-wrapper {
display: grid;
}

.select-value-wrapper > span {
grid-area: 1 / 1;
}
.select-value-wrapper > span:first-child {
visibility: hidden;
}

:global(.icon) {
width: 18px;
height: 18px;
Expand Down
Loading