Skip to content

Commit 1ad0f4b

Browse files
chore(combobox-web): create utils getInputLabel and use it to check if has label
1 parent fd41180 commit 1ad0f4b

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

packages/pluggableWidgets/combobox-web/src/components/MultiSelection/MultiSelection.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import classNames from "classnames";
22
import { Fragment, KeyboardEvent, ReactElement, createElement, useMemo, useRef } from "react";
33
import { ClearButton } from "../../assets/icons";
44
import { MultiSelector, SelectionBaseProps } from "../../helpers/types";
5-
import { getSelectedCaptionsPlaceholder } from "../../helpers/utils";
5+
import { getInputLabel, getSelectedCaptionsPlaceholder } from "../../helpers/utils";
66
import { useDownshiftMultiSelectProps } from "../../hooks/useDownshiftMultiSelectProps";
7-
import { useHasLabel } from "../../hooks/useHasLabel";
87
import { useLazyLoading } from "../../hooks/useLazyLoading";
98
import { ComboboxWrapper } from "../ComboboxWrapper";
109
import { InputPlaceholder } from "../Placeholder";
@@ -65,7 +64,9 @@ export function MultiSelection({
6564
readOnly: selector.options.filterType === "none",
6665
"aria-required": ariaRequired.value
6766
});
68-
const hasLabel = useHasLabel(inputProps.id);
67+
68+
const inputLabel = getInputLabel(inputProps.id);
69+
const hasLabel = useMemo(() => Boolean(inputLabel), [inputLabel]);
6970

7071
const memoizedselectedCaptions = useMemo(
7172
() => getSelectedCaptionsPlaceholder(selector, selectedItems),

packages/pluggableWidgets/combobox-web/src/components/SingleSelection/SingleSelection.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import classNames from "classnames";
22
import { Fragment, ReactElement, createElement, useMemo, useRef } from "react";
33
import { ClearButton } from "../../assets/icons";
44
import { SelectionBaseProps, SingleSelector } from "../../helpers/types";
5+
import { getInputLabel } from "../../helpers/utils";
56
import { useDownshiftSingleSelectProps } from "../../hooks/useDownshiftSingleSelectProps";
6-
import { useHasLabel } from "../../hooks/useHasLabel";
77
import { useLazyLoading } from "../../hooks/useLazyLoading";
88
import { ComboboxWrapper } from "../ComboboxWrapper";
99
import { InputPlaceholder } from "../Placeholder";
@@ -65,7 +65,9 @@ export function SingleSelection({
6565
},
6666
{ suppressRefError: true }
6767
);
68-
const hasLabel = useHasLabel(inputProps.id);
68+
69+
const inputLabel = getInputLabel(inputProps.id);
70+
const hasLabel = useMemo(() => Boolean(inputLabel), [inputLabel]);
6971

7072
return (
7173
<Fragment>

packages/pluggableWidgets/combobox-web/src/helpers/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,7 @@ function sortSelections(
149149
}
150150
return newValueIds;
151151
}
152+
153+
export function getInputLabel(inputId: string): Element | null {
154+
return document.querySelector(`label[for="${inputId}"]`);
155+
}

packages/pluggableWidgets/combobox-web/src/hooks/useHasLabel.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)