From 63ebbfd458a110299a18915592e3159006b2cbee Mon Sep 17 00:00:00 2001 From: Brion Date: Tue, 19 Nov 2024 14:19:25 +0530 Subject: [PATCH] fix(react): fix `Select` label margin issues --- .../src/components/Select/Select.stories.mdx | 49 ++++++++++++------- .../react/src/components/Select/Select.tsx | 37 +++++++++++--- .../react/src/components/Select/select.scss | 8 +-- 3 files changed, 64 insertions(+), 30 deletions(-) diff --git a/packages/react/src/components/Select/Select.stories.mdx b/packages/react/src/components/Select/Select.stories.mdx index 9d840437..182639b4 100644 --- a/packages/react/src/components/Select/Select.stories.mdx +++ b/packages/react/src/components/Select/Select.stories.mdx @@ -1,10 +1,11 @@ import {ArgsTable, Source, Story, Canvas, Meta} from '@storybook/addon-docs'; import {useArgs} from '@storybook/client-api'; import dedent from 'ts-dedent'; -import StoryConfig from '../../../.storybook/story-config.ts'; import Select from './Select.tsx'; -import MenuItem from '../MenuItem'; +import StoryConfig from '../../../.storybook/story-config.ts'; import FormControl from '../FormControl/FormControl.tsx'; +import MenuItem from '../MenuItem/MenuItem.tsx'; +import Stack from '../Stack/Stack.tsx'; export const meta = { component: Select, @@ -14,18 +15,34 @@ export const meta = { export const Template = args => { - const [{open, anchor, onChange, label}, updateArgs] = useArgs(); + const [{anchor}, updateArgs] = useArgs(); return ( - - - - ) + + + + + + + + + ); }; # Select @@ -39,11 +56,7 @@ export const Template = args => { The `Select` component is used to create a select input. - - {Template.bind({})} - + {Template.bind({})} ## Props diff --git a/packages/react/src/components/Select/Select.tsx b/packages/react/src/components/Select/Select.tsx index f9ee684d..18614411 100644 --- a/packages/react/src/components/Select/Select.tsx +++ b/packages/react/src/components/Select/Select.tsx @@ -61,23 +61,23 @@ const Select: ForwardRefExoticComponent = forwardRef( InputLabelProps = { disableAnimation: true, focused: false, - shrink: false, + shrink: true, }, label, name, required, + size = 'small', + variant = 'outlined', ...rest }: SelectProps, ref: Ref, ): ReactElement => { - const classes: string = clsx('oxygen-select', className); - const labelProps: MuiInputLabelProps = { ...{ disableAnimation: true, focused: false, required, - shrink: false, + shrink: true, }, ...InputLabelProps, }; @@ -89,12 +89,37 @@ const Select: ForwardRefExoticComponent = forwardRef( id={name} htmlFor={name} {...labelProps} - className={clsx('oxygen-select-static-label', InputLabelProps?.className)} + className={clsx( + /** + * @deprecated Use the `OxygenSelectLabel-root` class instead. + * This will be removed in the next major release (v3.0.0). + * Tracker: https://github.com/wso2/oxygen-ui/issues/274 + */ + 'oxygen-select-static-label', + 'OxygenSelectLabel-root', + InputLabelProps?.className, + )} > {label} )} - + ); }, diff --git a/packages/react/src/components/Select/select.scss b/packages/react/src/components/Select/select.scss index f9e9af79..834853cd 100644 --- a/packages/react/src/components/Select/select.scss +++ b/packages/react/src/components/Select/select.scss @@ -1,7 +1,3 @@ -// TODO: Remove this when we have a better solution. -// This seems like a bug from the MUI side. -// Tracker: https://github.com/wso2/oxygen-ui/issues/171 -.oxygen-select-static-label { - margin-top: -40px; - margin-left: -14px; +.OxygenSelect-root { + margin-top: 24px; }