Skip to content

Commit bd8c818

Browse files
authored
Merge pull request #1 from tableflowhq/feature/dropdown-fixes
Added mark for required options. Updated placeholder to enable selection
2 parents 087c4a4 + 014e169 commit bd8c818

File tree

4 files changed

+47
-27
lines changed

4 files changed

+47
-27
lines changed

src/Input/Input.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,6 @@ Dropdown.args = {
135135
"Option III": { value: "3" },
136136
"Option IV": { value: "4" },
137137
"Option V": { value: "5" },
138+
"Option V": { value: "required", required: true },
138139
},
139140
};

src/Input/index.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default function Input({ as = "input", label, icon, iconAfter, error, opt
6060
);
6161
}
6262

63-
function Select({ options = {}, ...props }: InputProps) {
63+
function Select({ options = {}, placeholder, ...props }: InputProps) {
6464
const [open, setOpen] = useState(false);
6565

6666
const onChangeOption = (e: any) => {
@@ -101,14 +101,26 @@ function Select({ options = {}, ...props }: InputProps) {
101101

102102
return (
103103
<>
104-
<input {...props} value={selectedKey} className={classes([style.select, open && style.open])} readOnly onFocus={onFocus} />
104+
<input
105+
{...props}
106+
value={selectedKey && `${selectedKey} ${options[selectedKey]?.required ? "*" : ""}`}
107+
className={classes([style.select, open && style.open])}
108+
readOnly
109+
onFocus={onFocus}
110+
placeholder={placeholder}
111+
/>
105112

106113
<div className={style.optionsRef} ref={setRef} />
107114

108115
{open && (
109116
<Portal>
110117
<div className={style.options} style={optionsPosition} ref={setRefPortal}>
111118
<div className={style.inner} ref={ref}>
119+
{placeholder && (
120+
<button key={-1} className={classes([style.option, style.placeholder])} onClick={onChangeOption}>
121+
{placeholder}
122+
</button>
123+
)}
112124
{Object.keys(options).map((k, i) => (
113125
<button
114126
key={k}
@@ -117,7 +129,7 @@ function Select({ options = {}, ...props }: InputProps) {
117129
{...options[k]}
118130
onClick={onChangeOption}
119131
autoFocus={i === 0}>
120-
{k}
132+
{k} {options[k].required && <span className={style.requiredMark}>*</span>}
121133
</button>
122134
))}
123135
</div>

src/Input/style/Input.module.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@
196196
&.selected {
197197
background-color: var(--color-background-menu-hover);
198198
}
199+
&.placeholder {
200+
color: var(--color-text-soft);
201+
}
202+
}
203+
.requiredMark {
204+
color: var(--color-text-error);
199205
}
200206
}
201207
}

src/Input/types/index.ts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,32 @@ import { ButtonHTMLAttributes, InputHTMLAttributes, ReactElement } from "react";
22
import { IconType } from "../../Icon/types";
33

44
export type inputTypes =
5-
| "date"
6-
| "datetime-local"
7-
| "email"
8-
| "file"
9-
| "month"
10-
| "number"
11-
| "password"
12-
| "search"
13-
| "tel"
14-
| "text"
15-
| "time"
16-
| "url"
17-
| "week";
5+
| "date"
6+
| "datetime-local"
7+
| "email"
8+
| "file"
9+
| "month"
10+
| "number"
11+
| "password"
12+
| "search"
13+
| "tel"
14+
| "text"
15+
| "time"
16+
| "url"
17+
| "week";
1818

1919
export type InputVariants = "fluid" | "small";
20+
export type InputOption = ButtonHTMLAttributes<HTMLButtonElement> & { required: boolean };
2021

2122
export type InputProps = InputHTMLAttributes<HTMLInputElement> &
22-
InputHTMLAttributes<HTMLSelectElement> &
23-
InputHTMLAttributes<HTMLTextAreaElement> & {
24-
as?: "input" | "textarea";
25-
label?: string | ReactElement;
26-
icon?: IconType;
27-
iconAfter?: IconType | ReactElement;
28-
error?: string;
29-
options?: { [key: string]: ButtonHTMLAttributes<HTMLButtonElement> };
30-
variants?: InputVariants[];
31-
type?: inputTypes;
32-
};
23+
InputHTMLAttributes<HTMLSelectElement> &
24+
InputHTMLAttributes<HTMLTextAreaElement> & {
25+
as?: "input" | "textarea";
26+
label?: string | ReactElement;
27+
icon?: IconType;
28+
iconAfter?: IconType | ReactElement;
29+
error?: string;
30+
options?: { [key: string]: InputOption };
31+
variants?: InputVariants[];
32+
type?: inputTypes;
33+
};

0 commit comments

Comments
 (0)