Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
09d6ee3
Remove commented-out code from DefaultSelect component
Nov 20, 2025
2bca61f
Remove unused code and comments from DefaultSelect component
Nov 20, 2025
fbc389a
Merge branch 'main' of https://github.com/PxTools/PxWeb2
Nov 24, 2025
c0abf7a
Refactor DefaultSelect component to use native select element for bet…
Nov 24, 2025
70ed382
Refactor DefaultSelect component for improved readability and formatting
Nov 24, 2025
5de589b
Refactor Select component for improved readability and maintainability
Nov 24, 2025
6c1652f
Improve formatting of Select component test for better readability
Nov 24, 2025
201da53
Refactor Select component styles and tests for improved organization …
Dec 8, 2025
dff40c6
Refactor Select component by removing unnecessary whitespace and comm…
Dec 8, 2025
bc28e62
Refactor Select component by removing unused styles and commented cod…
Dec 12, 2025
fa9b483
Fix formatting issues in Select component styles and TypeScript file …
Dec 12, 2025
b8ae5e2
Remove redundant width property from optionLayout class for improved …
Dec 12, 2025
ed1d21e
Refactor DefaultSelect component to improve placeholder handling and …
Dec 12, 2025
471e89a
Refactor DefaultSelect component to improve JSX formatting for better…
Dec 12, 2025
c8ef351
Refactor Select component to remove unused placeholder prop and updat…
Dec 15, 2025
2c93491
Clean up Select component styles and improve JSX formatting for bette…
Dec 15, 2025
0fb1781
Refactor Select component tests to improve clarity and remove comment…
Dec 15, 2025
ece91cf
Refactor Select component tests for improved clarity and consistency …
Dec 15, 2025
c7c038c
Refactor Select component to enhance RTL support and improve default …
Dec 15, 2025
5d7f3cb
Refactor Select component for improved readability and consistency in…
Dec 15, 2025
86b3ae7
Merge branch 'main' into feature/PXWEB2-934-native-select
Dec 19, 2025
9873072
refactor: simplify direction handling in Select component styles
Dec 22, 2025
a486b3d
refactor: streamline Icon component usage in DefaultSelect
Dec 22, 2025
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
42 changes: 23 additions & 19 deletions packages/pxweb2-ui/src/lib/components/Select/Select.module.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
@use '../../../../style-dictionary/dist/scss/fixed-variables.scss' as fixed;

.iconColor {
--px-icon-color: var(--px-color-icon-action);
}
@use '../../text-styles.scss';

// ----------------------------------------------------
// --- CSS classes for the default Select component ---
Expand All @@ -22,13 +19,24 @@
align-self: stretch;
}

.contentStyle {
.selectWrapper {
display: flex;
position: relative;
width: 100%;
}

.optionLayout {
appearance: none;
border: none;
width: 100%;
height: 48px;

display: flex;
padding: fixed.$spacing-2 fixed.$spacing-3;
align-items: center;
gap: fixed.$spacing-2;
align-self: stretch;
position: relative;

border-radius: var(--px-border-radius-medium);
box-shadow: inset 0 0 0 2px var(--px-color-border-default);
Expand All @@ -54,24 +62,20 @@
}
}

.optionLayout {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
line-clamp: 1;
flex: 1 0 0;
}

.optionTypography {
overflow: hidden;
color: var(--px-color-text-default);
text-overflow: ellipsis;
}

.visuallyHidden {
display: none;
}

.iconColor {
--px-icon-color: var(--px-color-icon-action);
position: absolute;
font-size: 1.5rem;
pointer-events: none;
align-self: center;
background: var(--px-color-surface-default);
inset-inline-end: fixed.$spacing-3;
}

// --------------------------------------------------------
// --- CSS classes for the Variabelbox Select component ---
// --------------------------------------------------------
Expand Down
37 changes: 19 additions & 18 deletions packages/pxweb2-ui/src/lib/components/Select/Select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,7 @@ describe('Select', () => {
expect(labelWrapper).toBeDefined();
});

it('should display placeholder when no option is selected', () => {
const placeholder = 'Select an option';
render(
<Select
label="Test Select"
placeholder={placeholder}
options={mockOptions}
onChange={mockOnChange}
addModal={mockAddModal}
removeModal={mockRemoveModal}
/>,
);

expect(screen.getByText(placeholder)).toBeDefined();
});

it('should display selected option when provided', () => {
it('should display selected option when provided', async () => {
render(
<Select
label="Test Select"
Expand All @@ -81,10 +65,27 @@ describe('Select', () => {
/>,
);

expect(screen.getByText(mockOptions[0].label)).toBeDefined();
const option = await screen.findByText(mockOptions[0].label);
expect(option).toBeInTheDocument();
});
});

it('should display selected option when provided', () => {
render(
<Select
label="Test Select"
options={mockOptions}
selectedOption={mockOptions[0]}
onChange={mockOnChange}
addModal={mockAddModal}
removeModal={mockRemoveModal}
/>,
);

const nativeSelect = screen.getByRole('combobox', { name: /test select/i });
expect(nativeSelect).toHaveDisplayValue('Option 1');
});

describe('VariableBoxSelect variant', () => {
const defaultProps = {
label: 'Test Select',
Expand Down
57 changes: 31 additions & 26 deletions packages/pxweb2-ui/src/lib/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Icon } from '../Icon/Icon';
import Modal from '../Modal/Modal';
import Radio from '../Radio/Radio';
import { getIconDirection } from '../../util/util';
import i18next from 'i18next';

export type SelectProps = {
variant?: 'default' | 'inVariableBox';
Expand Down Expand Up @@ -62,9 +63,7 @@ export function Select({
hideLabel={hideLabel}
label={label}
options={ops}
placeholder={placeholder}
selectedOption={selectedOption}
onChange={onChange}
tabIndex={tabIndex}
className={cssClasses}
/>
Expand Down Expand Up @@ -96,9 +95,7 @@ type DefaultSelectProps = Pick<
| 'hideLabel'
| 'label'
| 'options'
| 'placeholder'
| 'selectedOption'
| 'onChange'
| 'tabIndex'
| 'className'
>;
Expand All @@ -107,10 +104,8 @@ function DefaultSelect({
hideLabel,
label,
options,
placeholder,
selectedOption,
onChange,
tabIndex,
tabIndex = 0,
className = '',
}: Readonly<DefaultSelectProps>) {
const cssClasses = className.length > 0 ? ' ' + className : '';
Expand All @@ -126,26 +121,30 @@ function DefaultSelect({
{label}
</Label>
</div>
<div
className={cl(classes.contentStyle)}
tabIndex={tabIndex}
onClick={() => {
openOptions(options); // TODO: Get option
onChange(options[0]); // TODO: Use selected option
}}
onKeyUp={(event) => {
if (event.key === ' ' || event.key === 'Enter') {
openOptions(options); // TODO: Get option
onChange(options[0]); // TODO: Use selected option

<div className={cl(classes.selectWrapper)}>
<select
aria-label={label}
className={cl(classes.optionLayout, classes['bodyshort-medium'])}
defaultValue={
selectedOption ? String(selectedOption.value) : undefined
}
}}
>
<BodyShort
size="medium"
className={cl(classes.optionLayout, classes.optionTypography)}
>
{selectedOption ? selectedOption.label : placeholder}
</BodyShort>
{options.map((o) => (
<option
key={String(o.value)}
value={String(o.value)}
className={cl(classes['bodyshort-medium'])}
tabIndex={tabIndex}
// Use uncontrolled select with initial value from selectedOption
defaultValue={
selectedOption ? String(selectedOption.value) : undefined
}
>
{o.label}
</option>
))}
</select>
<Icon iconName="ChevronDown" className={cl(classes.iconColor)}></Icon>
</div>
</div>
Expand Down Expand Up @@ -310,7 +309,13 @@ function VariableBoxSelect({
{selectedItem ? selectedItem.label : placeholder}
</BodyShort>
</div>
<Icon iconName={chevronIcon} className={cl(classes.iconColor)}></Icon>
<Icon
iconName={chevronIcon}
className={cl(
classes.iconColor,
i18next.dir() === 'rtl' ? classes.rtl : classes.ltr,
)}
></Icon>
</div>
<div className={cl(classes.divider)}></div>
{isModalOpen && (
Expand Down