Skip to content

Commit b0c6de4

Browse files
committed
[@mantine/core] Input: Add inputSize prop to set size html attribute on the input element
1 parent 276050e commit b0c6de4

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

packages/@mantine/core/src/components/Input/Input.story.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function WithinDisabledFieldset() {
1515
export function Error() {
1616
return (
1717
<div style={{ padding: 40, maxWidth: 400 }}>
18-
<Input placeholder="With error" error />
18+
<Input placeholder="With error" error inputSize="5" />
1919
</div>
2020
);
2121
}

packages/@mantine/core/src/components/Input/Input.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ describe('@mantine/core/Input', () => {
157157
expect(screen.getByRole('textbox')).not.toHaveAttribute('disabled');
158158
});
159159

160+
it('allows setting size attribute on the input element', () => {
161+
render(<Input inputSize="5" />);
162+
expect(screen.getByRole('textbox')).toHaveAttribute('size', '5');
163+
});
164+
160165
it('exposes compound components', () => {
161166
expect(Input.Wrapper).toBe(InputWrapper);
162167
expect(Input.Label).toBe(InputLabel);

packages/@mantine/core/src/components/Input/Input.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ export interface __InputProps {
100100

101101
/** Determines whether the input should have red border and red text color when the `error` prop is set, `true` by default */
102102
withErrorStyles?: boolean;
103+
104+
/** `size` prop added to the input element */
105+
inputSize?: string;
103106
}
104107

105108
export interface InputProps extends BoxProps, __InputProps, StylesApiProps<InputFactory> {
@@ -195,6 +198,7 @@ export const Input = polymorphicFactory<InputFactory>((_props, ref) => {
195198
withAria,
196199
withErrorStyles,
197200
mod,
201+
inputSize,
198202
...others
199203
} = props;
200204

@@ -267,6 +271,7 @@ export const Input = polymorphicFactory<InputFactory>((_props, ref) => {
267271
required={required}
268272
mod={{ disabled, error: !!error && withErrorStyles }}
269273
variant={variant}
274+
__size={inputSize}
270275
{...getStyles('input')}
271276
/>
272277

packages/@mantine/core/src/core/Box/Box.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export interface BoxProps extends MantineStyleProps {
2828
/** CSS variables defined on root component element */
2929
__vars?: CssVarsProp;
3030

31+
/** `size` property passed down the HTML element */
32+
__size?: string;
33+
3134
/** Breakpoint above which the component is hidden with `display: none` */
3235
hiddenFrom?: MantineBreakpoint;
3336

@@ -75,6 +78,7 @@ const _Box = forwardRef<
7578
lightHidden,
7679
darkHidden,
7780
renderRoot,
81+
__size,
7882
...others
7983
},
8084
ref
@@ -108,6 +112,7 @@ const _Box = forwardRef<
108112
}),
109113
'data-variant': variant,
110114
'data-size': isNumberLike(size) ? undefined : size || undefined,
115+
size: __size,
111116
...getBoxMod(mod),
112117
...rest,
113118
};

0 commit comments

Comments
 (0)