Skip to content

Commit

Permalink
Fix width DateField (#1422)
Browse files Browse the repository at this point in the history
  • Loading branch information
takurinton committed Sep 21, 2023
1 parent 4cf84df commit e37770b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-rice-push.md
@@ -0,0 +1,5 @@
---
"ingred-ui": patch
---

fix width DateField
8 changes: 5 additions & 3 deletions src/components/DateField/DateField/DateField.tsx
@@ -1,4 +1,4 @@
import React, { forwardRef, memo } from "react";
import React, { forwardRef, memo, useMemo } from "react";
import { ErrorText, Icon, Input, Spacer } from "../..";
import { useDateField } from "../useDateField";
import { useMergeRefs } from "../../../hooks/useMergeRefs";
Expand Down Expand Up @@ -38,11 +38,12 @@ export type DateFieldProps = {

const DateField = forwardRef<HTMLInputElement, DateFieldProps>(
function DateField(
{ errorText, disabled = false, onClick, ...rest },
{ errorText, format = "YYYY-MM-DD", disabled = false, onClick, ...rest },
propRef,
) {
const theme = useTheme();
const { ref: inputRef, ...props } = useDateField({ ...rest });
const width = useMemo(() => format.length * 10, [format]);
const { ref: inputRef, ...props } = useDateField({ format, ...rest });
const ref = useMergeRefs<HTMLInputElement>(propRef, inputRef);

return (
Expand All @@ -54,6 +55,7 @@ const DateField = forwardRef<HTMLInputElement, DateFieldProps>(
style={{ border: "none" }}
error={!!errorText}
disabled={disabled}
width={width}
{...props}
/>
<CalendarIcon disabled={disabled} onClick={onClick}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DateField/DateField/styled.ts
Expand Up @@ -6,7 +6,7 @@ export const InputContainer = styled.div<{
}>`
display: flex;
align-items: center;
width: 150px;
width: fit-content;
/* MEMO: for calendar icon */
padding: 0 8px 0 0;
border: 0;
Expand Down

0 comments on commit e37770b

Please sign in to comment.