Skip to content

Commit 826d9d4

Browse files
authored
Fix S2 ComboBox and NumberField custom width (#6782)
1 parent efe2f80 commit 826d9d4

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

packages/@react-spectrum/s2/src/ComboBox.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import CheckmarkIcon from '../ui-icons/Checkmark';
4242
import ChevronIcon from '../ui-icons/Chevron';
4343
import {createContext, CSSProperties, forwardRef, ReactNode, useCallback, useContext, useImperativeHandle, useRef, useState} from 'react';
4444
import {createFocusableRef, useFocusableRef} from '@react-spectrum/utils';
45-
import {field, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
45+
import {field, fieldInput, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
4646
import {FieldErrorIcon, FieldGroup, FieldLabel, HelpText, Input} from './Field';
4747
import {FocusableRef, HelpTextProps, SpectrumLabelableProps} from '@react-types/shared';
4848
import {FormContext, useFormProps} from './Form';
@@ -240,19 +240,12 @@ function ComboBox<T extends object>(props: ComboBoxProps<T>, ref: FocusableRef<H
240240
isInvalid={isInvalid}
241241
size={size}
242242
styles={style({
243+
...fieldInput(),
243244
paddingStart: 'edge-to-text',
244245
// better way to do this one? it's not actually half, they are
245246
// [9, 4], [12, 6], [15, 8], [18, 8]
246247
// also noticed that our measurement is including the border, making the padding too much
247-
paddingEnd: '[calc(self(height, self(minHeight)) * 3 / 16)]',
248-
width: {
249-
default: 208,
250-
size: {
251-
S: 192,
252-
L: 224,
253-
XL: 240
254-
}
255-
}
248+
paddingEnd: '[calc(self(height, self(minHeight)) * 3 / 16)]'
256249
})({size})}>
257250
<InputContext.Consumer>
258251
{ctx => (

packages/@react-spectrum/s2/src/NumberField.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import ChevronIcon from '../ui-icons/Chevron';
2525
import {createFocusableRef, useFocusableRef} from '@react-spectrum/utils';
2626
import {CSSProperties, ForwardedRef, forwardRef, ReactNode, useContext, useImperativeHandle, useMemo, useRef} from 'react';
2727
import Dash from '../ui-icons/Dash';
28-
import {field, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
28+
import {field, fieldInput, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
2929
import {FieldErrorIcon, FieldGroup, FieldLabel, HelpText, Input} from './Field';
3030
import {filterDOMProps, mergeProps, mergeRefs} from '@react-aria/utils';
3131
import {FocusableRef, HelpTextProps, SpectrumLabelableProps} from '@react-types/shared';
@@ -284,19 +284,11 @@ function NumberField(props: NumberFieldProps, ref: FocusableRef<HTMLDivElement>)
284284
isInvalid={isInvalid}
285285
size={size}
286286
styles={style({
287+
...fieldInput(),
287288
paddingStart: 'edge-to-text',
288289
paddingEnd: 0,
289-
width: {
290-
default: 'full',
291-
size: {
292-
S: 192,
293-
M: 208,
294-
L: 224,
295-
XL: 240
296-
}
297-
},
298290
cursor: 'default'
299-
})({size, isCollapsed})}>
291+
})({size})}>
300292
<InputContext.Consumer>
301293
{ctx => (
302294
<InputContext.Provider value={{...ctx, ref: mergeRefs((ctx as any)?.ref, inputRef)}}>

packages/@react-spectrum/s2/stories/ComboBox.stories.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212

1313
import {Button, ComboBox, ComboBoxItem, ComboBoxSection, Content, ContextualHelp, Footer, Form, Header, Heading, Link, Text} from '../src';
1414
import {categorizeArgTypes} from './utils';
15+
import {ComboBoxProps} from 'react-aria-components';
1516
import DeviceDesktopIcon from '../s2wf-icons/S2_Icon_DeviceDesktop_20_N.svg';
1617
import DeviceTabletIcon from '../s2wf-icons/S2_Icon_DeviceTablet_20_N.svg';
1718
import type {Meta, StoryObj} from '@storybook/react';
19+
import {style} from '../style/spectrum-theme' with {type: 'macro'};
1820

1921
const meta: Meta<typeof ComboBox<any>> = {
2022
component: ComboBox,
@@ -30,19 +32,18 @@ const meta: Meta<typeof ComboBox<any>> = {
3032
export default meta;
3133
type Story = StoryObj<typeof ComboBox<any>>;
3234

33-
export const Example: Story = {
34-
render: (args) => (
35-
<ComboBox {...args}>
36-
<ComboBoxItem>Chocolate</ComboBoxItem>
37-
<ComboBoxItem>Mint</ComboBoxItem>
38-
<ComboBoxItem>Strawberry</ComboBoxItem>
39-
<ComboBoxItem>Vanilla</ComboBoxItem>
40-
<ComboBoxItem>Chocolate Chip Cookie Dough</ComboBoxItem>
41-
</ComboBox>
42-
),
43-
args: {
44-
label: 'Ice cream flavor'
45-
}
35+
export const Example = (args: ComboBoxProps<any>) => (
36+
<ComboBox {...args}>
37+
<ComboBoxItem>Chocolate</ComboBoxItem>
38+
<ComboBoxItem>Mint</ComboBoxItem>
39+
<ComboBoxItem>Strawberry</ComboBoxItem>
40+
<ComboBoxItem>Vanilla</ComboBoxItem>
41+
<ComboBoxItem>Chocolate Chip Cookie Dough</ComboBoxItem>
42+
</ComboBox>
43+
);
44+
45+
Example.args = {
46+
label: 'Ice cream flavor'
4647
};
4748

4849
export const Sections: Story = {
@@ -210,3 +211,11 @@ ContextualHelpExample.parameters = {
210211
}
211212
}
212213
};
214+
215+
export const CustomWidth = (args: any) => <Example {...args} styles={style({width: 384})} />;
216+
CustomWidth.args = Example.args;
217+
CustomWidth.parameters = {
218+
docs: {
219+
disable: true
220+
}
221+
};

0 commit comments

Comments
 (0)