Skip to content

Commit 750f11f

Browse files
committed
style(FR-1795): fix value content style of Select when dropdown opens (#4866)
# Enhance BAISelect Component with Custom Styling Improves the visual feedback in dropdown selects by: 1. Moving custom select styles from CSS file to the BAISelect component 2. Adding opacity effect to images and tags when dropdown is open 3. Replacing standard Select with BAISelect in ImageEnvironmentSelectFormItems 4. Adding proper spacing with gap property to tag containers | Before | After | |---------|--------| | ![image.png](https://app.graphite.com/user-attachments/assets/66baf591-c1b9-4158-be12-441ec7cdfa3f.png) | ![image.png](https://app.graphite.com/user-attachments/assets/7d31ccd2-fb0e-450b-8264-f305962b7b76.png) |
1 parent ede84ba commit 750f11f

5 files changed

Lines changed: 51 additions & 92 deletions

File tree

packages/backend.ai-ui/setupTests.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@
44
// learn more: https://github.com/testing-library/jest-dom
55
import './src/__test__/matchMedia.mock';
66
import '@testing-library/jest-dom';
7+
8+
// Mock ResizeObserver for Ant Design v6 components
9+
global.ResizeObserver = jest.fn().mockImplementation(() => ({
10+
observe: jest.fn(),
11+
unobserve: jest.fn(),
12+
disconnect: jest.fn(),
13+
}));

packages/backend.ai-ui/src/components/BAISelect.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,33 @@ const useStyles = createStyles(({ css, token }) => ({
3737
}
3838
}
3939
`,
40+
customStyle: css`
41+
/* Change the opacity of images and tags in the select option when the dropdown is open */
42+
&.ant-select-open .ant-select-content .ant-select-content-value img,
43+
&.ant-select-open
44+
.ant-select-content
45+
.ant-select-content-value
46+
span.ant-tag {
47+
opacity: 0.5;
48+
}
49+
50+
/* TODO: re-enable this style after fixing flickering when theme changes */
51+
/* Add a gradient effect to the right side of the dropdown to indicate more content */
52+
/* & .ant-select-content::after {
53+
content: '';
54+
position: absolute;
55+
top: 0;
56+
right: 0;
57+
bottom: 0;
58+
width: 10px;
59+
background: linear-gradient(
60+
to right,
61+
transparent,
62+
${token.colorBgContainer}
63+
);
64+
z-index: 2;
65+
} */
66+
`,
4067
}));
4168

4269
export interface BAISelectProps<
@@ -131,11 +158,11 @@ function BAISelect<
131158
});
132159
}}
133160
ref={ref}
134-
className={
135-
ghost
136-
? classNames(styles.ghostSelect, selectProps.className)
137-
: selectProps.className
138-
}
161+
className={classNames(
162+
selectProps.className,
163+
styles.customStyle,
164+
ghost && styles.ghostSelect,
165+
)}
139166
onPopupScroll={(e) => {
140167
if (atBottomStateChange || endReached) handlePopupScroll(e);
141168
selectProps.onPopupScroll?.(e);

packages/backend.ai-ui/src/components/BAIStatistic.test.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import BAIStatistic from './BAIStatistic';
2-
import { render, screen, waitFor } from '@testing-library/react';
3-
import userEvent from '@testing-library/user-event';
2+
import { render, screen, fireEvent } from '@testing-library/react';
43

54
// Mock useTranslation
65
jest.mock('react-i18next', () => ({
@@ -408,7 +407,6 @@ describe('BAIStatistic', () => {
408407

409408
describe('Tooltip Content', () => {
410409
it('should show tooltip with current/total when hovering over progress bar', async () => {
411-
const user = userEvent.setup();
412410
const { container } = render(
413411
<BAIStatistic
414412
title="Memory"
@@ -423,14 +421,14 @@ describe('BAIStatistic', () => {
423421
const progressBar = container.querySelector('.ant-progress');
424422
expect(progressBar).toBeInTheDocument();
425423

426-
// Hover over the progress bar to trigger tooltip
427-
await user.hover(progressBar!);
424+
// Hover over the progress bar to trigger tooltip using fireEvent
425+
// Note: userEvent.hover() doesn't work well with Ant Design tooltips
426+
// due to pointer-events: none on child elements
427+
fireEvent.mouseOver(progressBar!);
428428

429429
// Wait for tooltip to appear and verify content
430-
await waitFor(() => {
431-
const tooltipContent = screen.getByText('4 GB / 8 GB');
432-
expect(tooltipContent).toBeInTheDocument();
433-
});
430+
const tooltipContent = await screen.findByText('4 GB / 8 GB');
431+
expect(tooltipContent).toBeInTheDocument();
434432
});
435433

436434
it('should not show tooltip when progressMode is hidden', () => {

react/src/components/ImageEnvironmentSelectFormItems.css

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

react/src/components/ImageEnvironmentSelectFormItems.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
import { useThemeMode } from '../hooks/useThemeMode';
1515
import DoubleTag from './DoubleTag';
1616
// @ts-ignore
17-
import cssRaw from './ImageEnvironmentSelectFormItems.css?raw';
1817
import ImageMetaIcon from './ImageMetaIcon';
1918
import { ImageTags } from './ImageTags';
2019
import TextHighlighter from './TextHighlighter';
@@ -28,7 +27,7 @@ import {
2827
theme,
2928
Typography,
3029
} from 'antd';
31-
import { BAIFlex } from 'backend.ai-ui';
30+
import { BAIFlex, BAISelect } from 'backend.ai-ui';
3231
import _ from 'lodash';
3332
import React, { useEffect, useMemo, useRef, useState } from 'react';
3433
import { useTranslation } from 'react-i18next';
@@ -349,7 +348,6 @@ const ImageEnvironmentSelectFormItems: React.FC<
349348

350349
return (
351350
<>
352-
<style>{cssRaw}</style>
353351
<Form.Item
354352
className="image-environment-select-form-item"
355353
name={['environments', 'environment']}
@@ -375,7 +373,7 @@ const ImageEnvironmentSelectFormItems: React.FC<
375373
]}
376374
style={{ marginBottom: 10 }}
377375
>
378-
<Select
376+
<BAISelect
379377
ref={envSelectRef}
380378
showSearch={{
381379
searchValue: environmentSearch,
@@ -543,7 +541,7 @@ const ImageEnvironmentSelectFormItems: React.FC<
543541
);
544542
})
545543
)}
546-
</Select>
544+
</BAISelect>
547545
</Form.Item>
548546
<Form.Item
549547
noStyle
@@ -581,7 +579,7 @@ const ImageEnvironmentSelectFormItems: React.FC<
581579
},
582580
]}
583581
>
584-
<Select
582+
<BAISelect
585583
ref={versionSelectRef}
586584
popupMatchSelectWidth={false}
587585
onChange={(value) => {
@@ -797,7 +795,7 @@ const ImageEnvironmentSelectFormItems: React.FC<
797795
);
798796
},
799797
)}
800-
</Select>
798+
</BAISelect>
801799
</Form.Item>
802800
);
803801
}}

0 commit comments

Comments
 (0)