Skip to content

Commit

Permalink
Merge pull request #2779 from github/robertbrignull/dropdown-disabled
Browse files Browse the repository at this point in the history
Adjust styling of disabled dropdowns to make their state clearer
  • Loading branch information
robertbrignull authored Sep 5, 2023
2 parents a3ce9f5 + 074f3fb commit 247ba4e
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions extensions/ql-vscode/src/view/common/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import * as React from "react";
import { ChangeEvent } from "react";
import { styled } from "styled-components";

const StyledDropdown = styled.select`
const DISABLED_VALUE = "-";

const StyledDropdown = styled.select<{ disabled?: boolean }>`
width: 100%;
height: calc(var(--input-height) * 1px);
background: var(--vscode-dropdown-background);
color: var(--vscode-foreground);
border: none;
border-width: 0 5px 0 0;
padding: 2px 6px 2px 8px;
opacity: ${(props) =>
props.disabled ? "var(--disabled-opacity)" : "inherit"};
`;

type Props = {
Expand All @@ -31,18 +35,20 @@ type Props = {
export function Dropdown({ value, options, disabled, onChange }: Props) {
return (
<StyledDropdown
value={disabled ? undefined : value}
value={disabled ? DISABLED_VALUE : value}
disabled={disabled}
onChange={onChange}
>
{!disabled && (
<>
{options.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</>
{disabled ? (
<option key={DISABLED_VALUE} value={DISABLED_VALUE}>
{DISABLED_VALUE}
</option>
) : (
options.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))
)}
</StyledDropdown>
);
Expand Down

0 comments on commit 247ba4e

Please sign in to comment.