Skip to content

Commit 76fb682

Browse files
authored
v1.6.5
**Fixes** - Updates id generation to reduce risk of id collision #471
2 parents fa0b741 + 1c102c5 commit 76fb682

9 files changed

Lines changed: 11 additions & 11 deletions

File tree

-11.6 KB
Loading
-11.6 KB
Loading
-14.4 KB
Loading
-11.9 KB
Loading

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@yext/search-ui-react",
3-
"version": "1.6.4",
3+
"version": "1.6.5",
44
"description": "A library of React Components for powering Yext Search integrations",
55
"author": "slapshot@yext.com",
66
"license": "BSD-3-Clause",

src/components/Dropdown/Dropdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function Dropdown(props: PropsWithChildren<DropdownProps>): JSX.Element {
6464
} = props;
6565

6666
const containerRef = useRef<HTMLDivElement>(null);
67-
const screenReaderUUID = useId();
67+
const screenReaderUUID = useId('dropdown');
6868
const [screenReaderKey, setScreenReaderKey] = useState<number>(0);
6969
const [hasTyped, setHasTyped] = useState<boolean>(false);
7070
const [childrenWithDropdownItemsTransformed, items] = useMemo(() => {
@@ -295,4 +295,4 @@ function getTransformedChildrenAndItemData(children: ReactNode): [ReactNode, Dro
295295
return createElement(DropdownItemWithIndex, { ...props, index: items.length - 1 });
296296
}));
297297
return [childrenWithDropdownItemsTransformed, items];
298-
}
298+
}

src/components/Filters/CheckboxOption.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export function CheckboxOption(props: CheckboxOptionProps): JSX.Element | null {
7979
resultsCount
8080
} = props;
8181
const cssClasses = useComposedCssClasses(builtInCssClasses, props.customCssClasses);
82-
const optionId = useId();
82+
const optionId = useId('facet');
8383
const { selectFilter, filters, applyFilters } = useFiltersContext();
8484

8585
const handleClick = useCallback((checked: boolean) => {

src/hooks/useId.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { useLayoutEffect } from "./useLayoutEffect";
66

77
let serverHandoffComplete = false;
88
let id = 0;
9-
function genId(): string {
9+
function genId(baseName: string): string {
1010
++id;
11-
return id.toString();
11+
return baseName + '-' + id.toString();
1212
}
1313

1414
// Workaround for https://github.com/webpack/webpack/issues/14814
@@ -28,14 +28,14 @@ const maybeReactUseId: undefined | (() => string) = (React as any)[
2828
* @see Docs https://reach.tech/auto-id
2929
*/
3030

31-
export function useId(): string {
31+
export function useId(baseName: string): string {
3232
if (maybeReactUseId !== undefined) {
3333
return maybeReactUseId();
3434
}
3535

3636
// If this instance isn't part of the initial render, we don't have to do the
3737
// double render/patch-up dance. We can just generate the ID and return it.
38-
const initialId = (serverHandoffComplete ? genId() : '');
38+
const initialId = (serverHandoffComplete ? genId(baseName) : '');
3939
const [id, setId] = useState(initialId);
4040

4141
useLayoutEffect(() => {
@@ -44,7 +44,7 @@ export function useId(): string {
4444
// rendering flicker, though it'll make the first render slower (unlikely
4545
// to matter, but you're welcome to measure your app and let us know if
4646
// it's a problem).
47-
setId(genId());
47+
setId(genId(baseName));
4848
}
4949
}, [id]);
5050

0 commit comments

Comments
 (0)