🐛(react) fix props not recognized on the input element
The props propagation was adding unknown props to the input element, which was causing an error warning to be displayed in the console.
This commit is contained in:
committed by
Anthony LC
parent
8086a48672
commit
c7000f37d2
@@ -2,14 +2,27 @@ import React, { InputHTMLAttributes, forwardRef } from "react";
|
||||
import classNames from "classnames";
|
||||
import { Field, FieldProps } from ":/components/Forms/Field";
|
||||
|
||||
export type SwitchOnlyProps = {
|
||||
label?: string;
|
||||
labelSide?: "left" | "right";
|
||||
};
|
||||
|
||||
export type SwitchProps = InputHTMLAttributes<HTMLInputElement> &
|
||||
FieldProps & {
|
||||
label?: string;
|
||||
labelSide?: "left" | "right";
|
||||
};
|
||||
FieldProps &
|
||||
SwitchOnlyProps;
|
||||
|
||||
export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
|
||||
({ label, labelSide = "left", ...props }: SwitchProps, ref) => {
|
||||
const {
|
||||
compact,
|
||||
fullWidth,
|
||||
rightText,
|
||||
state,
|
||||
text,
|
||||
textItems,
|
||||
...inputProps
|
||||
} = props;
|
||||
|
||||
return (
|
||||
<label
|
||||
className={classNames(
|
||||
@@ -26,7 +39,7 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
|
||||
<div className="c__checkbox__container">
|
||||
{label && <div className="c__checkbox__label">{label}</div>}
|
||||
<div className="c__switch__rail__wrapper">
|
||||
<input type="checkbox" {...props} ref={ref} />
|
||||
<input type="checkbox" {...inputProps} ref={ref} />
|
||||
<div className="c__switch__rail" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user