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

amitha/fix/text-field-focus-animation-in-dialog #333

Merged
merged 4 commits into from
Nov 15, 2021
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
2 changes: 1 addition & 1 deletion src/components/Combobox/Combobox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const Combobox = forwardRef(
setActiveItemIndex(index);
if (mouseClick) {
// set focus on input again
inputRef.current?.focus();
requestAnimationFrame(() => inputRef.current?.focus());
}
setIsActiveByKeyboard(!mouseClick);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ exports[`<Combobox /> renders correctly with empty props 1`] = `
aria-label="Search for content"
aria-owns=""
autoComplete="off"
autoFocus={false}
className="combobox--wrapper-search search_component input-component__input input-component__input--has-icon"
disabled={false}
id="combobox-search"
Expand Down Expand Up @@ -135,7 +134,6 @@ exports[`<Combobox /> renders correctly with one option 1`] = `
aria-label="Search for content"
aria-owns=""
autoComplete="off"
autoFocus={false}
className="combobox--wrapper-search search_component input-component__input input-component__input--has-icon"
disabled={false}
id="combobox-search"
Expand Down Expand Up @@ -262,7 +260,6 @@ exports[`<Combobox /> renders correctly with options and categories 1`] = `
aria-label="Search for content"
aria-owns=""
autoComplete="off"
autoFocus={false}
className="combobox--wrapper-search search_component input-component__input input-component__input--has-icon"
disabled={false}
id="combobox-search"
Expand Down
13 changes: 10 additions & 3 deletions src/components/TextField/TextField.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import React, { forwardRef, useRef, useMemo, useCallback } from "react";
import React, { forwardRef, useRef, useMemo, useCallback, useEffect } from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
import useDebounceEvent from "../../hooks/useDebounceEvent";
Expand All @@ -13,7 +13,8 @@ import { SIZES } from "../../constants/sizes";
import useMergeRefs from "../../hooks/useMergeRefs";
import { useButton } from "@react-aria/button";

const NOOP = () => {};
const NOOP = () => {
};

const EMPTY_OBJECT = { primary: "", secondary: "", label: "" };
const TextField = forwardRef(
Expand Down Expand Up @@ -104,6 +105,13 @@ const TextField = forwardRef(
elementType: "div"
});

useEffect(() => {
if (inputRef.current && autoFocus) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add cancelAnimationFrame on the return function of the useEffect please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orrgottlieb found that i missed combo aswell please look there too :)

const animationFrame = requestAnimationFrame(() => inputRef.current.focus());
return () => cancelAnimationFrame(animationFrame);
}
}, [inputRef, autoFocus]);

return (
<div
className={classNames("input-component", wrapperClassName, {
Expand All @@ -128,7 +136,6 @@ const TextField = forwardRef(
disabled={disabled}
readOnly={readonly}
ref={mergedRef}
autoFocus={autoFocus}
type={type}
id={id}
onBlur={onBlur}
Expand Down