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+Select): remove htmlSize #2697

Merged
merged 6 commits into from
Oct 30, 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
5 changes: 5 additions & 0 deletions .changeset/selfish-meals-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@digdir/designsystemet-react": major
---

Input+Select: Use native HTML `size` prop instead of `htmlSize`
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type PaginationButtonProps = {
* @default false
*/
'aria-current'?: AriaAttributes['aria-current'];
} & Omit<ButtonProps, 'icon' | 'loading' | 'size'>;
} & Omit<ButtonProps, 'icon' | 'loading'>;

export const PaginationButton = forwardRef<
HTMLButtonElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type ToggleGroupItemProps = {
* Generates a random value if not set.
**/
value?: string;
} & Omit<ButtonProps, 'loading' | 'size' | 'value'>;
} & Omit<ButtonProps, 'loading' | 'value'>;

/**
* A single item in a ToggleGroup.
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/components/form/Input/Input.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ Det er viktig at samme informasjon som vises i prefixet eller suffixet også er

<Canvas of={InputStories.Controlled} />

## Html Size
## Html size

`size` attributtet kan brukes for å angi bredden på tekstfeltet. Verdien kan være et tall fra 1 til 99.

<Canvas of={InputStories.HtmlSize} />

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/form/Input/Input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ export const Preview: Story = {
};
export const HtmlSize: Story = {
args: {
htmlSize: 10,
size: 10,
},
render: (args) => (
<Field>
<Label>Input with htmlSize</Label>
<Label>Input with size</Label>
<Input {...args} />
</Field>
),
Expand Down
10 changes: 4 additions & 6 deletions packages/react/src/components/form/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ type InputAttr = InputHTMLAttributes<HTMLInputElement>;
export type InputProps = {
/** Supported `input` types */
type?: InputAttr['type'];
/** Exposes the HTML `size` attribute.
* @default 20
/** Defines the width of <Input> in count of characters.
*/
htmlSize?: number;
size?: number;
/** Disables element
* @note Avoid using if possible for accessibility purposes
*/
Expand All @@ -19,7 +18,7 @@ export type InputProps = {
readOnly?: boolean;
/** Set role, i.e. `switch` when `checkbox` or `radio` */
role?: InputAttr['role'];
} & Omit<InputAttr, 'size' | 'prefix' | 'role' | 'type'> &
} & Omit<InputAttr, 'prefix' | 'role' | 'type'> &
DefaultProps;

/** Input field
Expand All @@ -30,14 +29,13 @@ export type InputProps = {
* ```
*/
export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
{ type = 'text', htmlSize, className, onChange, onClick, ...rest },
{ type = 'text', className, onChange, onClick, ...rest },
ref,
) {
return (
<input
className={cl(`ds-input`, className)}
ref={ref}
size={htmlSize}
type={type}
onChange={(event) => rest.readOnly || onChange?.(event)} // Make readonly work for checkbox / radio / switch
onClick={(event) => {
Expand Down
11 changes: 3 additions & 8 deletions packages/react/src/components/form/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,18 @@ export type SelectProps = {
* @default false
*/
readOnly?: boolean;
/** Exposes the HTML `size` attribute.
* @default 0
/** Defines the width of <Select> in count of characters.
*/
htmlSize?: number;
size?: number;
} & Omit<SelectHTMLAttributes<HTMLSelectElement>, 'size' | 'multiple'> &
DefaultProps;

export const Select = forwardRef<HTMLSelectElement, SelectProps>(
function Select(
{ className, htmlSize, onKeyDown, onMouseDown, ...rest },
ref,
) {
function Select({ className, onKeyDown, onMouseDown, ...rest }, ref) {
return (
<select
className={cl('ds-input', className)}
ref={ref}
size={htmlSize}
onKeyDown={(event) => {
if (event.key === 'Tab') return;
if (rest.readOnly) event.preventDefault(); // Make readonly work for select
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/form/Select/useSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type UseSelect = (props: SelectProps) => Omit<FormField, 'inputProps'> & {
};

/** Handles props for `Select` in context with `Fieldset` */
export const useSelect: UseSelect = (props) => {
export const useSelect: UseSelect = ({ size: htmlSize, ...props }) => {
const fieldset = useContext(FieldsetContext);
const {
inputProps: selectProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ Det er viktig at samme informasjon som vises i prefixet eller suffixet også er

<Canvas of={TextfieldStories.Controlled} />

## Html Size
## Html size

`size` attributtet kan brukes for å angi bredden på tekstfeltet. Verdien kan være et tall fra 1 til 99.

<Canvas of={TextfieldStories.HtmlSize} />

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/form/Textfield/Textfield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export type TextfieldProps = {
* @default 20
*/
htmlSize?: number;
} & Omit<FormFieldProps, 'size'> &
Omit<InputHTMLAttributes<HTMLInputElement>, 'size'> &
} & FormFieldProps &
InputHTMLAttributes<HTMLInputElement> &
DefaultProps;

/** Text input field
Expand Down
Loading