nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: gravity-ui/uikit
Pull request #421 (2022-12-13 13:57:57)

fix(Tooltip): preserve child ref


Patch:
diff --git a/src/components/Tooltip/Tooltip.tsx b/src/components/Tooltip/Tooltip.tsx
index 44c97a4a..7016951b 100644
--- a/src/components/Tooltip/Tooltip.tsx
+++ b/src/components/Tooltip/Tooltip.tsx
@@ -3,6 +3,7 @@ import React, {Children, cloneElement, useEffect, useState} from 'react';
 import {Popup, PopupPlacement} from '../Popup';
 import {useBoolean} from '../utils/useBoolean';
 import {block} from '../utils/cn';
+import {useForkRef} from '../utils/useForkRef';
 
 import './Tooltip.scss';
 
@@ -26,8 +27,6 @@ export const Tooltip = (props: TooltipProps) => {
     const [anchorElement, setAnchorElement] = useState<HTMLElement | null>(null);
     const tooltipVisible = useTooltipVisible(anchorElement, props);
 
-    const child = Children.only(children);
-
     const renderPopup = () => {
         return (
             <Popup
@@ -44,9 +43,14 @@ export const Tooltip = (props: TooltipProps) => {
         );
     };
 
+    const child = Children.only(children);
+    const childRef = (child as any).ref;
+
+    const ref = useForkRef(setAnchorElement, childRef);
+
     return (
         <>
-            {cloneElement(child, {ref: setAnchorElement})}
+            {cloneElement(child, {ref})}
             {anchorElement ? renderPopup() : null}
         </>
     );


Test patch:
diff --git a/src/components/Tooltip/__tests__/Tooltip.test.tsx b/src/components/Tooltip/__tests__/Tooltip.test.tsx
new file mode 100644
index 00000000..5de4f8ba
--- /dev/null
+++ b/src/components/Tooltip/__tests__/Tooltip.test.tsx
@@ -0,0 +1,15 @@
+import React from 'react';
+import {render} from '@testing-library/react';
+
+import {Tooltip} from '../Tooltip';
+
+test('should preserve ref on anchor element', () => {
+    const ref = jest.fn();
+    render(
+        <Tooltip content="text">
+            <button ref={ref} />
+        </Tooltip>,
+    );
+
+    expect(ref).toHaveBeenCalledTimes(1);
+});
Repository: gravity-ui/uikit
Pull request #517 (2023-01-31 11:30:19)

fix(Select): filter options when filter text is empty

gravity-ui-bot: [Preview](https://preview.gravity-ui.com/uikit/517/) is ready.
<!-- Sticky Pull Request Comment -->

Patch:
diff --git a/src/components/Select/Select.tsx b/src/components/Select/Select.tsx
index 9a820628..2729a230 100644
--- a/src/components/Select/Select.tsx
+++ b/src/components/Select/Select.tsx
@@ -85,14 +85,13 @@ export const Select = React.forwardRef<HTMLButtonElement, SelectProps>(function
     });
     const options = props.options || getOptionsFromChildren(props.children);
     const flattenOptions = getFlattenOptions(options);
-    const filteredFlattenOptions =
-        filterable && filter
-            ? getFilteredFlattenOptions({
-                  options: flattenOptions,
-                  filter,
-                  filterOption,
-              })
-            : flattenOptions;
+    const filteredFlattenOptions = filterable
+        ? getFilteredFlattenOptions({
+              options: flattenOptions,
+              filter,
+              filterOption,
+          })
+        : flattenOptions;
     const selectedOptionsContent = getSelectedOptionsContent(
         flattenOptions,
         value,


Test patch:
diff --git a/src/components/Select/__tests__/Select.filter.test.tsx b/src/components/Select/__tests__/Select.filter.test.tsx
index 1ebaf720..de43beb4 100644
--- a/src/components/Select/__tests__/Select.filter.test.tsx
+++ b/src/components/Select/__tests__/Select.filter.test.tsx
@@ -2,7 +2,7 @@ import React from 'react';
 import {cleanup} from '@testing-library/react';
 import userEvent from '@testing-library/user-event';
 import {TextInput} from '../../TextInput';
-import type {SelectProps} from '../types';
+import type {SelectOption, SelectProps} from '../types';
 import {TEST_QA, generateOptions, setup} from './utils';
 
 afterEach(() => {
@@ -84,4 +84,19 @@ describe('Select filter', () => {
         // filter shouldn`t work due to initialized filterOption
         expect(queryAllByRole('listitem').length).toBe(40);
     });
+
+    test('should filter options even if filter text is empty', async () => {
+        const filterOption = jest.fn((option: SelectOption) => option.value.endsWith('0'));
+        const {getByTestId, queryAllByRole} = setup({
+            options: generateOptions(40),
+            filterable: true,
+            filterOption,
+        });
+        const user = userEvent.setup();
+        const selectControl = getByTestId(TEST_QA);
+        await user.click(selectControl);
+        expect(filterOption).toHaveBeenCalled();
+        // 10, 20, 30, 40
+        expect(queryAllByRole('listitem').length).toBe(4);
+    });
 });