Skip to content

Commit

Permalink
fix(csr): 🐛 bug with mounted in checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
navin-moorthy committed Jan 4, 2022
1 parent 9d736d9 commit 9f2d4db
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type CheckboxProps = CheckboxInitialState &
export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
(props, ref) => {
const {
ssr,
csr,
label,
description,
labelProps,
Expand All @@ -29,7 +29,7 @@ export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
descriptionProps,
} = useCheckboxProps(props);

if (!ssr) {
if (csr) {
return null;
}

Expand Down
4 changes: 3 additions & 1 deletion src/checkbox/CheckboxProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
runIfFn,
splitProps,
} from "../utils";
import { useHasMounted } from "..";

import { USE_CHECKBOX_STATE_KEYS } from "./__keys";
import { CheckboxOwnProps, CheckboxProps } from "./Checkbox";
Expand Down Expand Up @@ -43,6 +44,7 @@ export const useCheckboxProps = (
const { icon, label, description } = state;
const { className, style, children, ...restProps } = checkboxProps;
const { componentProps } = getComponentProps(componentMap, children, state);
const mounted = useHasMounted();

const _icon: CheckboxState["icon"] =
componentProps?.iconProps?.children || icon;
Expand Down Expand Up @@ -88,7 +90,7 @@ export const useCheckboxProps = (
};

return {
ssr: isEmptyObject(componentProps),
csr: !isEmptyObject(componentProps) && !mounted,
state,
labelProps,
inputProps,
Expand Down
1 change: 0 additions & 1 deletion src/show-more/ShowMoreButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ export const ShowMoreButton = createComponent({
memo: true,
useHook: useShowMoreButton,
});
console.log("%cShowMoreButton", "color: #ff6600", ShowMoreButton);
3 changes: 1 addition & 2 deletions src/show-more/stories/ShowMoreHorizontal.component.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as React from "react";

import { ShowMore, ShowMoreButton, ShowMoreProps } from "../../index";
import { ShowMore, ShowMoreProps } from "../../index";

export const ShowMoreHorizontal: React.FC<ShowMoreProps> = props => {
console.log("%cShowMore", "color: #d0bfff", ShowMoreButton);
return (
<div className="overflow-x-scroll w-96">
<div className="flex flex-row items-center h-10 space-x-2 w-fit">
Expand Down
1 change: 0 additions & 1 deletion src/textarea/TextareaBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export const useTextareaBase = createHook<
const onChange = React.useCallback(
(event: React.ChangeEvent<HTMLTextAreaElement>) => {
onChangeRef.current?.(event);
console.log("%cevent", "color: #bfffc8", event);
if (event.defaultPrevented) return;

autoSizeOnChange?.(event);
Expand Down
6 changes: 2 additions & 4 deletions src/tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from "react";

import { useHasMounted } from "../hooks/useMounted";
import { useTheme } from "../theme";
import { cx, RenderProp, withIconA11y } from "../utils";

Expand All @@ -21,6 +20,7 @@ export type TooltipProps = TooltipInitialState &
export const Tooltip = React.forwardRef<HTMLInputElement, TooltipProps>(
(props, ref) => {
const {
csr,
state,
content,
prefix,
Expand All @@ -36,9 +36,7 @@ export const Tooltip = React.forwardRef<HTMLInputElement, TooltipProps>(
const suffixStyles = cx(theme.suffix);
const prefixStyles = cx(theme.prefix);

const mounted = useHasMounted();

if (!mounted) {
if (csr) {
return null;
}

Expand Down
5 changes: 3 additions & 2 deletions src/tooltip/TooltipProps.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";

import { getComponentProps, runIfFn } from "../index";
import { getComponentProps, runIfFn, useHasMounted } from "../index";
import { splitProps, withIconA11y } from "../utils";

import { USE_TOOLTIP_STATE_KEYS } from "./__keys";
Expand Down Expand Up @@ -41,6 +41,7 @@ export const useTooltipProps = (
children,
state,
);
const mounted = useHasMounted();

const referenceChildren: React.ReactNode = (referenceProps: any) =>
// @ts-ignore
Expand Down Expand Up @@ -78,7 +79,7 @@ export const useTooltipProps = (
};

return {
render: false,
csr: !mounted,
state,
arrowIcon,
content,
Expand Down

0 comments on commit 9f2d4db

Please sign in to comment.