Skip to content

Commit

Permalink
fix(clerk-js): Merge the two password onBlur behaviours into one and …
Browse files Browse the repository at this point in the history
…address spacing issues

fix(clerk-js): Add changeset
  • Loading branch information
raptisj committed Jul 19, 2023
1 parent 2e11664 commit 3864477
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-worms-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Merge the two password onBlur behaviours into one and address spacing issues
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ describe('PasswordPage', () => {
screen.getByText(/or more/i);
});
});
});
}, 10000);

it('results in error if the passwords do not match and persists', async () => {
const { wrapper } = await createFixtures(initConfig);
Expand Down
31 changes: 16 additions & 15 deletions packages/clerk-js/src/ui/elements/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,25 @@ function useFormTextAnimation() {
};
}

type CalculateConfigProps = {
recalculate: string | boolean | undefined;
};
type Px = number;
const useCalculateErrorTextHeight = () => {
const useCalculateErrorTextHeight = (config: CalculateConfigProps) => {
const [height, setHeight] = useState<Px>(24);

const calculateHeight = useCallback((element: HTMLElement | null) => {
if (element) {
const computedStyles = getComputedStyle(element);
const marginTop = parseInt(computedStyles.marginTop.replace('px', ''));
const calculateHeight = useCallback(
(element: HTMLElement | null) => {
if (element) {
const computedStyles = getComputedStyle(element);
const marginTop = parseInt(computedStyles.marginTop.replace('px', ''));

setHeight(prevHeight => {
const newHeight = 1.5 * marginTop + element.scrollHeight;
if (prevHeight < newHeight) {
return newHeight;
}
return prevHeight;
});
}
}, []);
const newHeight = 1.1 * marginTop + element.scrollHeight;
setHeight(newHeight);
}
},
[config.recalculate],
);
return {
height,
calculateHeight,
Expand All @@ -136,7 +137,7 @@ export const FormFeedback = (props: FormFeedbackProps) => {
const messageToDisplay = informationMessage || successMessage || errorMessage || warningMessage;
const isSomeMessageVisible = !!messageToDisplay;

const { calculateHeight, height } = useCalculateErrorTextHeight();
const { calculateHeight, height } = useCalculateErrorTextHeight({ recalculate: warningMessage });
const { getFormTextAnimation } = useFormTextAnimation();
const defaultElementDescriptors = {
error: descriptors.formFieldErrorText,
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/ui/primitives/FormErrorText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { applyVariants } = createVariants(theme => ({
marginTop: theme.sizes.$2,
animation: `${animations.textInSmall} ${theme.transitionDuration.$fast}`,
display: 'flex',
gap: theme.sizes.$2,
gap: theme.sizes.$1,
position: 'absolute',
top: '0',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/ui/primitives/FormSuccessText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const { applyVariants } = createVariants(theme => ({
marginTop: theme.sizes.$2,
animation: `${animations.textInSmall} ${theme.transitionDuration.$fast}`,
display: 'flex',
gap: theme.sizes.$2,
gap: theme.sizes.$1,
position: 'absolute',
top: '0',
},
Expand Down
25 changes: 3 additions & 22 deletions packages/clerk-js/src/ui/utils/useFormControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,9 @@ export const useFormControlFeedback = (opts: DebouncingOption): DebouncedFeedbac
hasPassedComplexity = false,
} = opts;

const canDisplayFeedback = useMemo(() => {
if (enableErrorAfterBlur) {
if (skipBlur) {
return true;
}
return hasLostFocus;
}
return true;
}, [enableErrorAfterBlur, hasLostFocus, skipBlur]);

const feedbackMemo = useMemo(() => {
const shouldDisplayErrorAsWarning = hasPassedComplexity ? errorText && !hasLostFocus : false;
const _errorText = !shouldDisplayErrorAsWarning && canDisplayFeedback ? errorText : '';
const shouldDisplayErrorAsWarning = hasPassedComplexity ? errorText : false;
const _errorText = !shouldDisplayErrorAsWarning ? errorText : '';
const _warningText = shouldDisplayErrorAsWarning ? errorText : warningText;
const _successfulText = successfulText;

Expand All @@ -226,16 +216,7 @@ export const useFormControlFeedback = (opts: DebouncingOption): DebouncedFeedbac
isFocused,
informationText: shouldShowInformationText ? informationText : '',
};
}, [
informationText,
enableErrorAfterBlur,
isFocused,
successfulText,
hasLostFocus,
errorText,
canDisplayFeedback,
skipBlur,
]);
}, [informationText, enableErrorAfterBlur, isFocused, successfulText, hasLostFocus, errorText, skipBlur]);

const debouncedState = useSetTimeout(feedbackMemo, delayInMs);

Expand Down

0 comments on commit 3864477

Please sign in to comment.