Skip to content

Commit 2f08256

Browse files
committed
👌 - fix: pr fixes
1 parent 24bce76 commit 2f08256

File tree

4 files changed

+82
-8
lines changed

4 files changed

+82
-8
lines changed

src/components/form/form/form.stories.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const playFormComponent = async ({
6565
const schoolYear = canvas.getByLabelText("Select school year", {
6666
exact: false,
6767
});
68+
const favouriteSport = canvas.getByLabelText("Favourite sport");
6869
const address = canvas.getByLabelText("Address");
6970
const address_addition = canvas.getByLabelText("Address (addition)");
7071
const dateOfBirth = canvas.getByLabelText("Date of birth", { exact: false });
@@ -140,6 +141,18 @@ const playFormComponent = async ({
140141
await expect(math).toBeChecked();
141142
await expectLogToBe(canvasElement, "courses", ["english", "math"]);
142143

144+
await userEvent.click(favouriteSport, { delay: 100 });
145+
const football = await canvas.findByText("Football");
146+
const tennis = await canvas.findByText("Tennis");
147+
await userEvent.click(football, { delay: 10 });
148+
await userEvent.click(tennis, { delay: 10 });
149+
await expect(favouriteSport).toHaveTextContent("FootballTennis");
150+
await expectLogToBe(
151+
canvasElement,
152+
"favourite_sport",
153+
typedResults ? ["football", "tennis"] : ["football", "tennis"],
154+
);
155+
143156
await userEvent.click(yes);
144157
await expect(yes).toBeChecked();
145158
await expectLogToBe(canvasElement, "subscribe_newsletter", "yes");
@@ -204,6 +217,20 @@ export const FormComponent: Story = {
204217
{ label: "Science", value: "science" },
205218
],
206219
},
220+
{
221+
options: [
222+
{ label: "Football", value: "football" },
223+
{ label: "Basketball", value: "basketball" },
224+
{ label: "Tennis", value: "tennis" },
225+
{ label: "Swimming", value: "swimming" },
226+
{ label: "Running", value: "running" },
227+
{ label: "Cycling", value: "cycling" },
228+
],
229+
name: "favourite_sport",
230+
placeholder: "Select favourite sport",
231+
label: "Favourite sport",
232+
multiple: true,
233+
},
207234
{
208235
label: "Receive newsletter",
209236
name: "subscribe_newsletter",
@@ -214,6 +241,7 @@ export const FormComponent: Story = {
214241
{ label: "No", value: "no" },
215242
],
216243
},
244+
217245
{
218246
label: "I have read and accept the terms and conditions",
219247
name: "accept_tos",
@@ -287,6 +315,20 @@ export const UsageWithFormik: Story = {
287315
{ label: "Science", value: "science" },
288316
],
289317
},
318+
{
319+
options: [
320+
{ label: "Football", value: "football" },
321+
{ label: "Basketball", value: "basketball" },
322+
{ label: "Tennis", value: "tennis" },
323+
{ label: "Swimming", value: "swimming" },
324+
{ label: "Running", value: "running" },
325+
{ label: "Cycling", value: "cycling" },
326+
],
327+
name: "favourite_sport",
328+
placeholder: "Select favourite sport",
329+
label: "Favourite sport",
330+
multiple: true,
331+
},
290332
{
291333
label: "Receive newsletter",
292334
name: "subscribe_newsletter",

src/components/form/select/select.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@
105105
align-items: center;
106106
padding: 0 0.5em; // TODO: spacing-h and spacing-v are too big for this. Add more tokens or hardcode?
107107
margin: calc(var(--spacing-h) / 4);
108-
border-radius: 9999px;
108+
border-radius: var(--border-radius-l);
109109
background-color: var(--page-color-accent);
110110
color: var(--typography-color-link);
111+
&-remove {
112+
margin-inline-start: 0.05em;
113+
}
111114
}
112115

113116
&__clear {

src/components/form/select/select.stories.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,15 @@ export const SelectSingle: Story = {
221221
export const SelectMultiple: Story = {
222222
args: {
223223
options: [
224-
{ label: "Freshman", value: "FR" },
225-
{ label: "Sophomore", value: "SO" },
226-
{ label: "Junior", value: "JR" },
227-
{ label: "Senior", value: "SR" },
228-
{ label: "Graduate", value: "GR" },
224+
{ label: "Football", value: "football" },
225+
{ label: "Basketball", value: "basketball" },
226+
{ label: "Tennis", value: "tennis" },
227+
{ label: "Swimming", value: "swimming" },
228+
{ label: "Running", value: "running" },
229+
{ label: "Cycling", value: "cycling" },
229230
],
230-
name: "school_year",
231-
placeholder: "Select school year",
231+
name: "favourite_sport",
232+
placeholder: "Select favourite sport",
232233
multiple: true,
233234
},
234235
decorators: [FORM_TEST_DECORATOR],

src/components/form/select/select.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import clsx from "clsx";
1818
import React, { useEffect } from "react";
1919

2020
import { gettextFirst, ucFirst } from "../../../lib";
21+
import { Button } from "../../button";
2122
import { Outline, Solid } from "../../icon";
2223
import { ChoiceFieldProps, Option } from "../choicefield";
2324
import { eventFactory } from "../eventFactory";
@@ -284,6 +285,33 @@ export const Select: React.FC<SelectProps> = ({
284285
return (
285286
<span key={i} className="mykn-select__pill">
286287
{options[i]?.label}
288+
<Button
289+
variant="transparent"
290+
className="mykn-select__pill-remove"
291+
aria-label={`Remove ${options[i]?.label}`}
292+
onClick={(e) => {
293+
e.stopPropagation(); // prevent dropdown from toggling
294+
const next = selectedIndices.filter((j) => j !== i);
295+
setSelectedIndices(next);
296+
297+
const detail = next.map((j) => options[j]);
298+
299+
const fakeInput = fakeInputRef.current!;
300+
const changeEvent = eventFactory(
301+
"change",
302+
detail,
303+
true,
304+
false,
305+
false,
306+
);
307+
fakeInput.dispatchEvent(changeEvent);
308+
onChange?.(
309+
changeEvent as unknown as React.ChangeEvent<HTMLSelectElement>,
310+
);
311+
}}
312+
>
313+
<Outline.XMarkIcon />
314+
</Button>
287315
</span>
288316
);
289317
}

0 commit comments

Comments
 (0)