Merge pull request #2779 from github/robertbrignull/dropdown-disabled

Adjust styling of disabled dropdowns to make their state clearer
This commit is contained in:
Robert
2023-09-05 16:20:40 +01:00
committed by GitHub

View File

@@ -2,13 +2,17 @@ import * as React from "react";
import { ChangeEvent } from "react"; import { ChangeEvent } from "react";
import { styled } from "styled-components"; import { styled } from "styled-components";
const StyledDropdown = styled.select` const DISABLED_VALUE = "-";
const StyledDropdown = styled.select<{ disabled?: boolean }>`
width: 100%; width: 100%;
height: calc(var(--input-height) * 1px); height: calc(var(--input-height) * 1px);
background: var(--vscode-dropdown-background); background: var(--vscode-dropdown-background);
color: var(--vscode-foreground); color: var(--vscode-foreground);
border: none; border-width: 0 5px 0 0;
padding: 2px 6px 2px 8px; padding: 2px 6px 2px 8px;
opacity: ${(props) =>
props.disabled ? "var(--disabled-opacity)" : "inherit"};
`; `;
type Props = { type Props = {
@@ -31,18 +35,20 @@ type Props = {
export function Dropdown({ value, options, disabled, onChange }: Props) { export function Dropdown({ value, options, disabled, onChange }: Props) {
return ( return (
<StyledDropdown <StyledDropdown
value={disabled ? undefined : value} value={disabled ? DISABLED_VALUE : value}
disabled={disabled} disabled={disabled}
onChange={onChange} onChange={onChange}
> >
{!disabled && ( {disabled ? (
<> <option key={DISABLED_VALUE} value={DISABLED_VALUE}>
{options.map((option) => ( {DISABLED_VALUE}
<option key={option.value} value={option.value}> </option>
{option.label} ) : (
</option> options.map((option) => (
))} <option key={option.value} value={option.value}>
</> {option.label}
</option>
))
)} )}
</StyledDropdown> </StyledDropdown>
); );