Skip to content

Commit

Permalink
v1.6.5
Browse files Browse the repository at this point in the history
**Fixes**

- Updates id generation to reduce risk of id collision #471
  • Loading branch information
Fondryext authored Oct 17, 2024
2 parents fa0b741 + 1c102c5 commit 76fb682
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 11 deletions.
Binary file modified .storybook/snapshots/__snapshots__/mapboxmap--custom-pin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .storybook/snapshots/__snapshots__/mapboxmap--multiple-pins.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .storybook/snapshots/__snapshots__/mapboxmap--primary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yext/search-ui-react",
"version": "1.6.4",
"version": "1.6.5",
"description": "A library of React Components for powering Yext Search integrations",
"author": "slapshot@yext.com",
"license": "BSD-3-Clause",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function Dropdown(props: PropsWithChildren<DropdownProps>): JSX.Element {
} = props;

const containerRef = useRef<HTMLDivElement>(null);
const screenReaderUUID = useId();
const screenReaderUUID = useId('dropdown');
const [screenReaderKey, setScreenReaderKey] = useState<number>(0);
const [hasTyped, setHasTyped] = useState<boolean>(false);
const [childrenWithDropdownItemsTransformed, items] = useMemo(() => {
Expand Down Expand Up @@ -295,4 +295,4 @@ function getTransformedChildrenAndItemData(children: ReactNode): [ReactNode, Dro
return createElement(DropdownItemWithIndex, { ...props, index: items.length - 1 });
}));
return [childrenWithDropdownItemsTransformed, items];
}
}
2 changes: 1 addition & 1 deletion src/components/Filters/CheckboxOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function CheckboxOption(props: CheckboxOptionProps): JSX.Element | null {
resultsCount
} = props;
const cssClasses = useComposedCssClasses(builtInCssClasses, props.customCssClasses);
const optionId = useId();
const optionId = useId('facet');
const { selectFilter, filters, applyFilters } = useFiltersContext();

const handleClick = useCallback((checked: boolean) => {
Expand Down
10 changes: 5 additions & 5 deletions src/hooks/useId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { useLayoutEffect } from "./useLayoutEffect";

let serverHandoffComplete = false;
let id = 0;
function genId(): string {
function genId(baseName: string): string {
++id;
return id.toString();
return baseName + '-' + id.toString();
}

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

export function useId(): string {
export function useId(baseName: string): string {
if (maybeReactUseId !== undefined) {
return maybeReactUseId();
}

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

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

Expand Down

0 comments on commit 76fb682

Please sign in to comment.