Skip to content

Commit

Permalink
fix: slideToggle console errors (#980)
Browse files Browse the repository at this point in the history
Closes D2IQ-98165
  • Loading branch information
nataliepina authored Jul 11, 2023
1 parent 3b7d0dd commit f8823f6
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/slideToggle/components/SlideToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export interface SlideToggleProps extends React.HTMLProps<HTMLInputElement> {
*/
appearance?: InputAppearance;
/**
* Whether or not the input is checked
* Whether or not the input is checked.
*/
checked?: boolean;
/**
* Unique identifier used for the input element
* Unique identifier used for the input element.
*/
id?: string;
/**
* The text or node content that appears next to the input
* The text or node content that appears next to the input.
*/
inputLabel: React.ReactNode | string;
/**
Expand All @@ -56,7 +56,7 @@ export interface SlideToggleProps extends React.HTMLProps<HTMLInputElement> {
*/
value?: string;
/**
* How the text content vertically aligns with the input
* How the text content vertically aligns with the input.
*/
vertAlign?: "center" | "top";
/**
Expand Down Expand Up @@ -87,22 +87,27 @@ const SlideToggle = (props: React.PropsWithRef<SlideToggleProps>) => {
onFocus,
...other
} = props;

const inputType = "SlideToggle";

const inputDataCy = [
`${inputType}-input`,
...(checked ? [`${inputType}-input.checked`] : []),
...(appearance && appearance !== InputAppearance.Standard
? [`${inputType}-input.${appearance}`]
: [])
].join(" ");

const parentDataCy = [
`${inputType}`,
...(checked ? [`${inputType}.checked`] : []),
...(appearance && appearance !== InputAppearance.Standard
? [`${inputType}.${appearance}`]
: [])
].join(" ");

const [hasFocus, setHasFocus] = React.useState<boolean>(false);

const handleFocus = e => {
setHasFocus(true);

Expand Down Expand Up @@ -131,14 +136,13 @@ const SlideToggle = (props: React.PropsWithRef<SlideToggleProps>) => {
<div className={cx(flexItem("shrink"), display("inherit"))}>
<>
<div className={cx(toggleContainer)}>
{/* eslint-disable jsx-a11y/role-has-required-aria-props */}
<input
type={inputType}
id={id}
className={visuallyHidden}
checked={checked}
defaultChecked={checked}
disabled={disabled}
value={value}
defaultValue={value}
aria-invalid={!isValid}
aria-describedby={describedByIds}
onFocus={handleFocus}
Expand Down

0 comments on commit f8823f6

Please sign in to comment.