Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

- Stabilized the dropdown anchor ref to prevent render loops and incorrect menu positioning.

## [3.6.0] - 2025-10-01

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function useGate(props: WidgetProps): DerivedPropsGate<RequiredProps> {
useEffect(() => {
gp.setProps(mapProps(props));
});

return gp.gate;
}

Expand Down
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import cn from "classnames";
import { useSelect, UseSelectProps } from "downshift";
import { observer } from "mobx-react-lite";
import { CSSProperties, FocusEventHandler, ReactElement, UIEventHandler } from "react";
import { CSSProperties, FocusEventHandler, ReactElement, Ref, UIEventHandler } from "react";
import { OptionWithState } from "../../typings/OptionWithState";
import { ClearButton } from "../base/ClearButton";
import { OptionsWrapper } from "../base/OptionsWrapper";
import { useFloatingMenu } from "../hooks/useFloatingMenu";
import { Arrow, classes } from "../picker-primitives";
import { useMergedRefs } from "../../utils/useMergedRefs";

interface SelectProps {
value: string;
Expand All @@ -33,18 +34,19 @@ export const Select = observer(function Select(props: SelectProps): ReactElement
const showClear = clearable && !isEmpty;

const { refs, floatingStyles } = useFloatingMenu(isOpen);

const { ref: downshiftRef, ...buttonProps } = getToggleButtonProps({
"aria-label": props.ariaLabel || "filter",
onFocus: props.onFocus
}) as ReturnType<typeof getToggleButtonProps> & { ref?: Ref<HTMLDivElement> };
const setReference = useMergedRefs<HTMLDivElement>(refs.setReference, downshiftRef);
return (
<div
ref={setReference}
className={cn(cls.root, "form-control", "variant-select", props.className)}
data-expanded={isOpen}
data-empty={isEmpty ? true : undefined}
style={props.style}
{...getToggleButtonProps({
"aria-label": props.ariaLabel || "filter",
ref: refs.setReference,
onFocus: props.onFocus
})}
{...buttonProps}
>
<div className={cls.inputContainer}>
<span className={cls.toggle}>{props.value}</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Ref, useCallback, useRef } from "react";

export function useMergedRefs<T>(...refs: Array<Ref<T> | null | undefined>): (node: T | null) => void {
const refsRef = useRef(refs);
refsRef.current = refs;

return useCallback((node: T | null) => {
for (const ref of refsRef.current) {
if (!ref) {
continue;
}

if (typeof ref === "function") {
ref(node);
} else {
ref.current = node;
}
}
}, []);
}
Loading