Skip to content

Commit

Permalink
fix(react): avoid wrapping Select with Box
Browse files Browse the repository at this point in the history
  • Loading branch information
brionmario committed Oct 24, 2023
1 parent 9813795 commit 1da8530
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
31 changes: 23 additions & 8 deletions packages/react/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,52 @@ import clsx from 'clsx';
import {forwardRef, ForwardRefExoticComponent, MutableRefObject, ReactElement} from 'react';
import {WithWrapperProps} from '../../models';
import {composeComponentDisplayName} from '../../utils';
import Box from '../Box';
import InputLabel, {InputLabelProps as MuiInputLabelProps} from '../InputLabel';
import './select.scss';

export interface SelectProps extends MuiSelectProps {
/**
* Props for the `InputLabel` component.
*/
InputLabelProps?: MuiInputLabelProps;
}

const COMPONENT_NAME: string = 'Select';

const Select: ForwardRefExoticComponent<SelectProps> & WithWrapperProps = forwardRef(
(props: SelectProps, ref: MutableRefObject<HTMLDivElement>): ReactElement => {
const {className, InputLabelProps, label, id, ...rest} = props;
const {className, InputLabelProps, label, name, required, ...rest} = props;

const classes: string = clsx('oxygen-select', className);

const labelProps: MuiInputLabelProps = {
...{
disableAnimation: true,
required,
shrink: false,
},
...InputLabelProps,
};

return (
<Box className={classes}>
<>
{label && (
<InputLabel id={id} {...InputLabelProps}>
<InputLabel id={name} htmlFor={name} {...labelProps}>
{label}
</InputLabel>
)}
<MuiSelect ref={ref} labelId={id} {...rest} />
</Box>
<MuiSelect ref={ref} labelId={name} className={classes} {...rest} />
</>
);
},
) as ForwardRefExoticComponent<SelectProps> & WithWrapperProps;

Select.displayName = composeComponentDisplayName(COMPONENT_NAME);
Select.muiName = COMPONENT_NAME;
Select.defaultProps = {};
Select.defaultProps = {
InputLabelProps: {
disableAnimation: true,
shrink: false,
},
};

export default Select;
21 changes: 0 additions & 21 deletions packages/react/src/components/Select/select.scss

This file was deleted.

0 comments on commit 1da8530

Please sign in to comment.