Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Select)!: remove deprecated props #1870

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 0 additions & 12 deletions src/components/Select/Select.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
position: relative;
}

/**
* Compact variant.
* TODO: remove treatment for compact, as it only adjusts the component width, not its overall padding
*/
.select--compact {
width: min-content;
}

.select-button--compact {
padding: var(--eds-size-half);
}

/**
* Label on top of the select trigger button to label the select field.
*/
Expand Down
51 changes: 5 additions & 46 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import PopoverListItem from '../PopoverListItem';
import Text from '../Text';
import styles from './Select.module.css';

export type OptionsAlignType = 'left' | 'right';
export type VariantType = 'compact' | 'full';

type SelectProps = ExtractProps<typeof Listbox> &
PopoverOptions & {
/**
Expand All @@ -40,27 +37,13 @@ type SelectProps = ExtractProps<typeof Listbox> &
* See: https://headlessui.com/react/listbox#using-with-html-forms
*/
name?: string;
/**
* Align select's popover to the left (default) or right of the trigger button's bottom edge.
* @deprecated
*/
optionsAlign?: OptionsAlignType;
/**
* Optional className for additional options menu styling.
*
* When not using the compact variant, if optionsClassName is provided please
* include the width property to define the options menu width.
*/
optionsClassName?: string;
/**
* The style of the select.
*
* Compact renders select trigger button that is only as wide as the content.
*
* This is **deprecated**. Please use utility classes to adjust the component width.
* @deprecated
*/
variant?: VariantType;
/**
* Visible text label for the component.
*/
Expand Down Expand Up @@ -118,8 +101,6 @@ type SelectButtonWrapperProps = {
};

type SelectContextType = PopoverContext & {
compact?: boolean;
optionsAlign?: OptionsAlignType;
optionsClassName?: string;
};

Expand Down Expand Up @@ -163,12 +144,10 @@ export function Select(props: SelectProps) {
modifiers = defaultPopoverModifiers,
name,
onFirstUpdate,
optionsAlign,
optionsClassName,
placement = 'bottom-start',
required,
strategy,
variant,
onChange: theirOnChange,
...other
} = props;
Expand All @@ -188,20 +167,12 @@ export function Select(props: SelectProps) {
}
}

// Translate old optionsAlign to placement values
// TODO: when removing optionsAlign, also remove this
const optionsPlacement: SelectProps['placement'] = optionsAlign
? ({ left: 'bottom-start', right: 'bottom-end' }[
optionsAlign
] as SelectProps['placement'])
: placement;

const [referenceElement, setReferenceElement] = useState(null);
const [popperElement, setPopperElement] = useState(null);
const { styles: popperStyles, attributes: popperAttributes } = usePopper(
referenceElement,
popperElement,
{ placement: optionsPlacement, modifiers, strategy, onFirstUpdate },
{ placement, modifiers, strategy, onFirstUpdate },
);

// Create a new value to track the internal state of Listbox. Added to work around
Expand All @@ -211,13 +182,7 @@ export function Select(props: SelectProps) {
other.value !== undefined ? other.value : other.defaultValue,
);

const compact = variant === 'compact';

const componentClassName = clsx(
styles['select'],
compact && styles['select--compact'],
className,
);
const componentClassName = clsx(styles['select'], className);
const sharedProps = {
className: componentClassName,
// Provide a wrapping <div> element for the select. This is needed so that any props
Expand All @@ -229,8 +194,7 @@ export function Select(props: SelectProps) {
};

const contextValue = Object.assign(
{ compact },
optionsAlign ? { optionsAlign } : null,
{},
optionsClassName ? { optionsClassName } : null,
{ setReferenceElement },
{ setPopperElement },
Expand Down Expand Up @@ -318,12 +282,7 @@ const SelectLabel = (props: SelectLabelProps) => {
*/
const SelectButton = function (props: SelectButtonProps) {
const { children, className, onClick: theirOnClick, ...other } = props;
const { compact, setReferenceElement } = useContext(SelectContext);

const componentClassName = clsx(
className,
compact && styles['select-button--compact'],
);
const { setReferenceElement } = useContext(SelectContext);

return (
<Listbox.Button
Expand All @@ -339,7 +298,7 @@ const SelectButton = function (props: SelectButtonProps) {
children(renderProps)
) : (
<SelectButtonWrapper
className={componentClassName}
className={className}
isOpen={renderProps.open}
onClick={(event) => {
theirOnClick && theirOnClick(event);
Expand Down
Loading