Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Sep 8, 2023
2 parents 467aaa8 + 8b12295 commit acd5732
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codegouvfr/react-dsfr",
"version": "0.75.3",
"version": "0.75.5",
"description": "French State Design System React integration library",
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions src/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const Header = memo(

const { Link } = getLink();

const quickAccessNode = (
const getQuickAccessNode = (suffix: string | null = null) => (
<ul className={fr.cx("fr-btns-group")}>
{quickAccessItems.map((quickAccessItem, i) => (
<li key={i}>
Expand All @@ -157,7 +157,7 @@ export const Header = memo(
<HeaderQuickAccessItem
id={`${id}-quick-access-item-${generateValidHtmlId({
"fallback": "",
"text": quickAccessItem.text
"text": `${quickAccessItem.text}${suffix ? `-${suffix}` : ""}`
})}-${i}`}
quickAccessItem={quickAccessItem}
/>
Expand Down Expand Up @@ -312,7 +312,7 @@ export const Header = memo(
classes.toolsLinks
)}
>
{quickAccessNode}
{getQuickAccessNode()}
</div>
)}

Expand Down Expand Up @@ -401,7 +401,7 @@ export const Header = memo(
classes.menuLinks
)}
>
{quickAccessNode}
{getQuickAccessNode("mobile")}
</div>
{navigation !== undefined &&
(navigation instanceof Array ? (
Expand Down
6 changes: 1 addition & 5 deletions src/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const Input = memo(
hintText,
hideLabel,
disabled = false,
iconId: iconId_props,
iconId,
classes = {},
style,
state = "default",
Expand Down Expand Up @@ -161,10 +161,6 @@ export const Input = memo(
/>
);

const iconId =
iconId_props ??
(nativeInputProps?.type === "date" ? "ri-calendar-line" : undefined);

return iconId === undefined ? (
nativeInputOrTextArea
) : (
Expand Down
17 changes: 15 additions & 2 deletions src/SelectNext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,24 @@ export type SelectProps<Options extends SelectProps.Option[]> = {
value?: Options[number]["value"];
onChange?: (
e: Omit<ChangeEvent<HTMLSelectElement>, "target" | "currentTarget"> & {
target: Omit<ChangeEvent<HTMLSelectElement>, "value"> & {
target: Omit<EventTarget & HTMLSelectElement, "value" | "selectedOptions"> & {
value: Options[number]["value"];
selectedOptions: HTMLCollectionOf<
Omit<HTMLOptionElement, "value"> & {
value: Options[number]["value"];
}
>;
};
currentTarget: Omit<ChangeEvent<HTMLSelectElement>, "value"> & {
currentTarget: Omit<
EventTarget & HTMLSelectElement,
"value" | "selectedOptions"
> & {
value: Options[number]["value"];
selectedOptions: HTMLCollectionOf<
Omit<HTMLOptionElement, "value"> & {
value: Options[number]["value"];
}
>;
};
}
) => void;
Expand Down
34 changes: 34 additions & 0 deletions test/types/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,37 @@ import { assert, type Equals } from "tsafe";
}}
/>;
}

{
const dogOrCatOptions = [
{
value: "dog",
label: "Dog"
},
{
value: "cat",
label: "Cat"
}
] as const;

type DogOrCat = typeof dogOrCatOptions[number]["value"];
type SelectTarget = Omit<EventTarget & HTMLSelectElement, "value" | "selectedOptions"> & {
value: DogOrCat;
selectedOptions: HTMLCollectionOf<Omit<HTMLOptionElement, "value"> & { value: DogOrCat }>;
};
<Select
label="Dog or cat person?"
options={[...dogOrCatOptions]}
placeholder="Select an option"
nativeSelectProps={{
"onChange": event => {
assert<Equals<typeof event["currentTarget"], SelectTarget>>();
assert<Equals<typeof event["target"], SelectTarget>>();
const selectedValues = Array.from(event.target.selectedOptions).map(
option => option.value
);
assert<Equals<typeof selectedValues, DogOrCat[]>>;
}
}}
/>;
}

0 comments on commit acd5732

Please sign in to comment.