Skip to content
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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- `BorderControl`: Improve labelling, tooltips and DOM structure ([#42348](https://github.com/WordPress/gutenberg/pull/42348/)).
- `BaseControl`: Set zero padding on `StyledLabel` to ensure cross-browser styling ([#42348](https://github.com/WordPress/gutenberg/pull/42348/)).
- `SelectControl`: Add flag for larger default size ([#42456](https://github.com/WordPress/gutenberg/pull/42456/)).
- `UnitControl`: Update unit select's focus styles to match input's ([#42383](https://github.com/WordPress/gutenberg/pull/42383)).

### Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import styled from '@emotion/styled';
import { COLORS, rtl } from '../../utils';
import type { SelectControlProps } from '../types';

interface SelectProps extends Pick< SelectControlProps, 'disabled' > {
interface SelectProps
extends Pick< SelectControlProps, '__next36pxDefaultSize' | 'disabled' > {
// Using `selectSize` instead of `size` to avoid a type conflict with the
// `size` HTML attribute of the `select` element.
selectSize?: SelectControlProps[ 'size' ];
Expand Down Expand Up @@ -45,11 +46,14 @@ const fontSizeStyles = ( { selectSize = 'default' }: SelectProps ) => {
`;
};

const sizeStyles = ( { selectSize = 'default' }: SelectProps ) => {
const sizeStyles = ( {
__next36pxDefaultSize,
selectSize = 'default',
}: SelectProps ) => {
const sizes = {
default: {
height: 30,
minHeight: 30,
height: 36,
minHeight: 36,
paddingTop: 0,
paddingBottom: 0,
},
Expand All @@ -67,16 +71,28 @@ const sizeStyles = ( { selectSize = 'default' }: SelectProps ) => {
},
};

const style = sizes[ selectSize ];
if ( ! __next36pxDefaultSize ) {
sizes.default = {
height: 30,
minHeight: 30,
paddingTop: 0,
paddingBottom: 0,
};
}

const style = sizes[ selectSize ] || sizes.default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which situation is sizes[ selectSize ] returning undefined, so that we have to fallback to the default? (same applies to the similar code change in the sizePaddings mixin)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a courtesy fallback in case a consumer passes an invalid size string.


return css( style );
};

const sizePaddings = ( { selectSize = 'default' }: SelectProps ) => {
const sizePaddings = ( {
__next36pxDefaultSize,
selectSize = 'default',
}: SelectProps ) => {
const sizes = {
default: {
paddingLeft: 8,
paddingRight: 24,
paddingLeft: 16,
paddingRight: 32,
},
small: {
paddingLeft: 8,
Expand All @@ -87,7 +103,15 @@ const sizePaddings = ( { selectSize = 'default' }: SelectProps ) => {
paddingRight: 32,
},
};
return rtl( sizes[ selectSize ] );

if ( ! __next36pxDefaultSize ) {
sizes.default = {
paddingLeft: 8,
paddingRight: 24,
};
}

return rtl( sizes[ selectSize ] || sizes.default );
};

// TODO: Resolve need to use &&& to increase specificity
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/select-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { BaseControlProps } from '../base-control/types';
export interface SelectControlProps
extends Pick<
InputBaseProps,
| '__next36pxDefaultSize'
| 'disabled'
| 'hideLabelFromVision'
| 'label'
Expand Down