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: Fixed Logistration page display #1431

Open
wants to merge 2 commits into
base: 2u-main
Choose a base branch
from
Open
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
36 changes: 35 additions & 1 deletion src/common-components/FormGroup.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';

import {
Form, TransitionReplace,
Expand All @@ -7,6 +7,38 @@

const FormGroup = (props) => {
const [hasFocus, setHasFocus] = useState(false);
const [isAutoFill, setIsAutoFill] = useState(false);
const inputRef = useRef(null);

useEffect(() => {
const checkAutoFill = () => {
if (inputRef.current) {
// Check both standard and vendor-prefixed autofill
const isAutoFillField = inputRef.current.matches(
':autofill, :-webkit-autofill',
);
setIsAutoFill(isAutoFillField);
}
};
const observer = new MutationObserver(checkAutoFill);
if (inputRef.current) {
// Check immediately on mount
checkAutoFill();

// Configure observer to watch style changes only
observer.observe(inputRef.current, {
attributes: true,
attributeFilter: ['style'], // Autofill often changes styles
});
// Fallback check for browser timing issues
const timeoutId = setTimeout(checkAutoFill, 100);
return () => {
observer.disconnect();
clearTimeout(timeoutId);
};
}
return () => observer.disconnect();

Check warning on line 40 in src/common-components/FormGroup.jsx

View check run for this annotation

Codecov / codecov/patch

src/common-components/FormGroup.jsx#L40

Added line #L40 was not covered by tests
}, []);

const handleFocus = (e) => {
setHasFocus(true);
Expand All @@ -23,6 +55,7 @@
return (
<Form.Group controlId={props.name} className={props.className} isInvalid={props.errorMessage !== ''}>
<Form.Control
ref={inputRef}
as={props.as}
readOnly={props.readOnly}
type={props.type}
Expand All @@ -39,6 +72,7 @@
controlClassName={props.borderClass}
trailingElement={props.trailingElement}
floatingLabel={props.floatingLabel}
isAutoFill={isAutoFill}
>
{props.options ? props.options() : null}
</Form.Control>
Expand Down