Skip to content

Commit 247ba4e

Browse files
Merge pull request #2779 from github/robertbrignull/dropdown-disabled
Adjust styling of disabled dropdowns to make their state clearer
2 parents a3ce9f5 + 074f3fb commit 247ba4e

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

extensions/ql-vscode/src/view/common/Dropdown.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import * as React from "react";
22
import { ChangeEvent } from "react";
33
import { styled } from "styled-components";
44

5-
const StyledDropdown = styled.select`
5+
const DISABLED_VALUE = "-";
6+
7+
const StyledDropdown = styled.select<{ disabled?: boolean }>`
68
width: 100%;
79
height: calc(var(--input-height) * 1px);
810
background: var(--vscode-dropdown-background);
911
color: var(--vscode-foreground);
10-
border: none;
12+
border-width: 0 5px 0 0;
1113
padding: 2px 6px 2px 8px;
14+
opacity: ${(props) =>
15+
props.disabled ? "var(--disabled-opacity)" : "inherit"};
1216
`;
1317

1418
type Props = {
@@ -31,18 +35,20 @@ type Props = {
3135
export function Dropdown({ value, options, disabled, onChange }: Props) {
3236
return (
3337
<StyledDropdown
34-
value={disabled ? undefined : value}
38+
value={disabled ? DISABLED_VALUE : value}
3539
disabled={disabled}
3640
onChange={onChange}
3741
>
38-
{!disabled && (
39-
<>
40-
{options.map((option) => (
41-
<option key={option.value} value={option.value}>
42-
{option.label}
43-
</option>
44-
))}
45-
</>
42+
{disabled ? (
43+
<option key={DISABLED_VALUE} value={DISABLED_VALUE}>
44+
{DISABLED_VALUE}
45+
</option>
46+
) : (
47+
options.map((option) => (
48+
<option key={option.value} value={option.value}>
49+
{option.label}
50+
</option>
51+
))
4652
)}
4753
</StyledDropdown>
4854
);

0 commit comments

Comments
 (0)