Skip to content

Commit

Permalink
fix: float input label when placeholder text is present
Browse files Browse the repository at this point in the history
  • Loading branch information
wp-aberg committed Dec 20, 2022
1 parent 6cb6f25 commit 6fe91b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ui/input-text/src/InputText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export interface InputTextProps
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
/** Callback executed when the input fires a focus event */
onFocus?: React.FocusEventHandler<HTMLInputElement>;
/** placeholder text */
placeholder?: string;
/** The input elements required attribute */
required?: boolean;
/** indicates there is a success */
Expand Down Expand Up @@ -127,6 +129,7 @@ export const InputText = React.forwardRef<HTMLInputElement, InputTextProps>(
onChange,
onFocus,
onButtonIconClick,
placeholder,
required,
success,
type = "text",
Expand Down Expand Up @@ -180,7 +183,7 @@ export const InputText = React.forwardRef<HTMLInputElement, InputTextProps>(

const [isFloating, handleOnFocus, handleOnBlur, handleOnChange] =
useFloating(
value || defaultValue || isAutofilled,
value || defaultValue || placeholder || isAutofilled,
onFocus,
onBlur,
onChange
Expand Down Expand Up @@ -278,6 +281,7 @@ export const InputText = React.forwardRef<HTMLInputElement, InputTextProps>(
onBlur={handleOnBlur}
onChange={handleOnChange}
onFocus={handleOnFocus}
placeholder={placeholder}
ref={internalRef}
required={required}
type={type}
Expand Down
1 change: 1 addition & 0 deletions ui/input-text/src/play.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ const ChromaticTemplate = () => (
label="Behavior"
defaultValue="Overflow - Four score and seven years ago"
/>
<Component label="Placeholder" placeholder="Example input" />
</Column>
);

Expand Down
6 changes: 5 additions & 1 deletion ui/input-textarea/src/InputTextarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export interface InputTextareaProps
onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
/** Callback executed when the input fires a focus event */
onFocus?: React.FocusEventHandler<HTMLTextAreaElement>;
/** placeholder text */
placeholder?: string;
/** The input elements required attribute */
required?: boolean;
/** The input element value for controlled components */
Expand Down Expand Up @@ -115,6 +117,7 @@ export const InputTextarea = React.forwardRef<
onBlur,
onChange,
required,
placeholder,
...props
},
ref
Expand Down Expand Up @@ -164,7 +167,7 @@ export const InputTextarea = React.forwardRef<
});

const [isFloating, handleFocus, handleBlur, handleChange] = useFloating(
value || defaultValue || isAutofilled,
value || defaultValue || placeholder || isAutofilled,
onFocus,
onBlur,
onChange
Expand All @@ -185,6 +188,7 @@ export const InputTextarea = React.forwardRef<
})}
required={required}
disabled={disabled}
placeholder={placeholder}
onFocus={handleFocus}
onBlur={handleBlur}
onChange={handleChange}
Expand Down

2 comments on commit 6fe91b4

@vercel
Copy link

@vercel vercel bot commented on 6fe91b4 Dec 20, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

wpds-ui-kit – ./build.washingtonpost.com

wpds-ui-kit.preview.now.washingtonpost.com
wpds-ui-kit-git-main.preview.now.washingtonpost.com
build.washingtonpost.com

@vercel
Copy link

@vercel vercel bot commented on 6fe91b4 Dec 20, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

wpds-ui-kit-storybook – ./

wpds-ui-kit-storybook.preview.now.washingtonpost.com
wpds-ui-kit-storybook-git-main.preview.now.washingtonpost.com

Please sign in to comment.