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

fix(Input): Added htmlSize prop to set native size attribute #1419

Merged
merged 7 commits into from
Jul 25, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shaggy-hornets-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': minor
---

Added `htmlSize` prop to the `Input` component which handles the native `size` attribute in `<input>`.
2 changes: 2 additions & 0 deletions apps/website/src/pages/docs/input.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ There are three different sizes, which can be specified using the `size` prop.
<AllExamples.InputSizesExample client:load />
</LiveExample>

Use the `htmlSize` prop for setting the native `size` attribute of the `<input>` element

### Status

Status messages are sometimes required for bringing warnings or errors to the user’s attention. For example, required fields that are left empty, spelling mistakes, or to notify a user the username they have entered is available. Note that the status is conveyed differently when [inline](#inline) styling is applied.
Expand Down
6 changes: 6 additions & 0 deletions packages/itwinui-react/src/core/Input/Input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ it('should render disabled component', () => {
);
});

it('should render with size prop using htmlSize', () => {
const { container } = render(<Input htmlSize='10' />);
assertBaseElement(container);
expect((container.querySelector('input') as HTMLInputElement).size).toBe(10);
});

it('should take class and style', () => {
const { container } = render(
<Input className='my-class' style={{ width: 50 }} />,
Expand Down
8 changes: 7 additions & 1 deletion packages/itwinui-react/src/core/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export type InputProps = {
* Modify size of the input.
*/
size?: 'small' | 'large';
/**
* Modify the native `size` attribute of the `<input>` element.
* The `width` or `inline-size` property must be unset in order to use this prop.
*/
htmlSize?: number;
};

/**
Expand All @@ -22,7 +27,7 @@ export type InputProps = {
* <Input size='small' />
*/
export const Input = React.forwardRef((props, ref) => {
const { size, className, ...rest } = props;
const { size, htmlSize, className, ...rest } = props;
const inputRef = React.useRef<HTMLInputElement>(null);
const refs = useMergedRefs<HTMLInputElement>(inputRef, ref);

Expand All @@ -31,6 +36,7 @@ export const Input = React.forwardRef((props, ref) => {
as='input'
className={cx('iui-input', className)}
data-iui-size={size}
size={htmlSize}
ref={refs}
{...rest}
/>
Expand Down