Skip to content

Commit d603954

Browse files
committed
fix(react): fix Select label margin issues
1 parent e10a6e1 commit d603954

File tree

3 files changed

+64
-30
lines changed

3 files changed

+64
-30
lines changed

packages/react/src/components/Select/Select.stories.mdx

+31-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import {ArgsTable, Source, Story, Canvas, Meta} from '@storybook/addon-docs';
22
import {useArgs} from '@storybook/client-api';
33
import dedent from 'ts-dedent';
4-
import StoryConfig from '../../../.storybook/story-config.ts';
54
import Select from './Select.tsx';
6-
import MenuItem from '../MenuItem';
5+
import StoryConfig from '../../../.storybook/story-config.ts';
76
import FormControl from '../FormControl/FormControl.tsx';
7+
import MenuItem from '../MenuItem/MenuItem.tsx';
8+
import Stack from '../Stack/Stack.tsx';
89

910
export const meta = {
1011
component: Select,
@@ -14,18 +15,34 @@ export const meta = {
1415
<Meta title={meta.title} component={meta.component} />
1516

1617
export const Template = args => {
17-
const [{open, anchor, onChange, label}, updateArgs] = useArgs();
18+
const [{anchor}, updateArgs] = useArgs();
1819
return (
19-
<FormControl fullWidth margin="dense">
20-
<Select label="Select WSO2 Product" defaultValue='Asgardeo' onChange={() => updateArgs({value: anchor})} {...args}>
21-
{['Asgardeo', 'Identity Server', 'Choreo', 'APIM'].map(anchor => (
22-
<MenuItem key={anchor} value={anchor}>
23-
{anchor}
24-
</MenuItem>
25-
))}
26-
</Select>
27-
</FormControl>
28-
)
20+
<Stack gap={2}>
21+
<FormControl fullWidth variant="standard">
22+
<Select
23+
label="Select WSO2 Product"
24+
defaultValue="Asgardeo"
25+
onChange={() => updateArgs({value: anchor})}
26+
{...args}
27+
>
28+
{['Asgardeo', 'Identity Server', 'Choreo', 'APIM'].map(_anchor => (
29+
<MenuItem key={_anchor} value={_anchor}>
30+
{_anchor}
31+
</MenuItem>
32+
))}
33+
</Select>
34+
</FormControl>
35+
<FormControl fullWidth variant="standard">
36+
<Select label="Select Version" defaultValue="v0.1.0" onChange={() => updateArgs({value: anchor})} {...args}>
37+
{['v0.1.0', 'v1.0.0', 'v2.0.0'].map(_anchor => (
38+
<MenuItem key={_anchor} value={_anchor}>
39+
{_anchor}
40+
</MenuItem>
41+
))}
42+
</Select>
43+
</FormControl>
44+
</Stack>
45+
);
2946
};
3047

3148
# Select
@@ -39,11 +56,7 @@ export const Template = args => {
3956
The `Select` component is used to create a select input.
4057

4158
<Canvas>
42-
<Story
43-
name="Overview"
44-
>
45-
{Template.bind({})}
46-
</Story>
59+
<Story name="Overview">{Template.bind({})}</Story>
4760
</Canvas>
4861

4962
## Props

packages/react/src/components/Select/Select.tsx

+31-6
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@ const Select: ForwardRefExoticComponent<SelectProps> = forwardRef(
6161
InputLabelProps = {
6262
disableAnimation: true,
6363
focused: false,
64-
shrink: false,
64+
shrink: true,
6565
},
6666
label,
6767
name,
6868
required,
69+
size = 'small',
70+
variant = 'outlined',
6971
...rest
7072
}: SelectProps,
7173
ref: Ref<HTMLDivElement>,
7274
): ReactElement => {
73-
const classes: string = clsx('oxygen-select', className);
74-
7575
const labelProps: MuiInputLabelProps = {
7676
...{
7777
disableAnimation: true,
7878
focused: false,
7979
required,
80-
shrink: false,
80+
shrink: true,
8181
},
8282
...InputLabelProps,
8383
};
@@ -89,12 +89,37 @@ const Select: ForwardRefExoticComponent<SelectProps> = forwardRef(
8989
id={name}
9090
htmlFor={name}
9191
{...labelProps}
92-
className={clsx('oxygen-select-static-label', InputLabelProps?.className)}
92+
className={clsx(
93+
/**
94+
* @deprecated Use the `OxygenSelectLabel-root` class instead.
95+
* This will be removed in the next major release (v3.0.0).
96+
* Tracker: https://github.com/wso2/oxygen-ui/issues/274
97+
*/
98+
'oxygen-select-static-label',
99+
'OxygenSelectLabel-root',
100+
InputLabelProps?.className,
101+
)}
93102
>
94103
{label}
95104
</InputLabel>
96105
)}
97-
<MuiSelect ref={ref} labelId={name} className={classes} {...rest} />
106+
<MuiSelect
107+
ref={ref}
108+
className={clsx(
109+
/**
110+
* @deprecated Use the `OxygenSelect-root` class instead.
111+
* This will be removed in the next major release (v3.0.0).
112+
* Tracker: https://github.com/wso2/oxygen-ui/issues/274
113+
*/
114+
'oxygen-select',
115+
'OxygenSelect-root',
116+
className,
117+
)}
118+
labelId={name}
119+
size={size}
120+
variant={variant}
121+
{...rest}
122+
/>
98123
</>
99124
);
100125
},
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// TODO: Remove this when we have a better solution.
2-
// This seems like a bug from the MUI side.
3-
// Tracker: https://github.com/wso2/oxygen-ui/issues/171
4-
.oxygen-select-static-label {
5-
margin-top: -40px;
6-
margin-left: -14px;
1+
.OxygenSelect-root {
2+
margin-top: 24px;
73
}

0 commit comments

Comments
 (0)