Skip to content

Commit

Permalink
fix: add autofocus style to input (#451)
Browse files Browse the repository at this point in the history
* fix: add autofocus style to input

* fix: rollback changes to lock

* fix: rollback changes to lock

* fix: rollback changes to lock

* fix: rollback changes to lock

* chore: commit save point
  • Loading branch information
artmsilva committed Aug 8, 2023
1 parent 542e02b commit 31ae39a
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 62 deletions.
4 changes: 4 additions & 0 deletions build.washingtonpost.com/public/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
<loc>https://build.washingtonpost.com/components/checkbox</loc>
</url>

<url>
<loc>https://build.washingtonpost.com/components/coach-marks</loc>
</url>

<url>
<loc>https://build.washingtonpost.com/components/container</loc>
</url>
Expand Down
37 changes: 16 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions ui/input-shared/src/InputShared.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as React from "react";
import { css, theme, globalCss } from "@washingtonpost/wpds-theme";

export const FloatingLabelStyles = {
fontSize: theme.fontSizes["075"],
lineHeight: theme.lineHeights["100"],
transform: `translateY(${theme.space["050"]})`,
};

export const sharedInputStyles = {
borderRadius: theme.radii["012"],
borderColor: theme.colors.subtle,
Expand Down Expand Up @@ -105,11 +111,12 @@ export const useFloating = (
onChange,
isAutofilled
): [
boolean,
React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>,
React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>,
(event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void
] => {
boolean,
React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>,
React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>,
(event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void
] => {

const [isFloating, setIsFloating] = React.useState(val ? true : false);
const [isTouched, setIsTouched] = React.useState(val ? true : false);
const [isFocused, setIsFocused] = React.useState(false);
Expand Down
18 changes: 8 additions & 10 deletions ui/input-text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
},
"peerDependencies": {
"@washingtonpost/wpds-assets": "^1.18.0",
"@washingtonpost/wpds-box": "*",
"@washingtonpost/wpds-button": "*",
"@washingtonpost/wpds-divider": "*",
"@washingtonpost/wpds-error-message": "*",
Expand All @@ -52,15 +51,14 @@
"dependencies": {
"@radix-ui/react-label": "^1.0.0",
"@washingtonpost/wpds-assets": "^1.18.0",
"@washingtonpost/wpds-box": "1.9.1",
"@washingtonpost/wpds-button": "1.9.1",
"@washingtonpost/wpds-error-message": "1.9.1",
"@washingtonpost/wpds-helper-text": "1.9.1",
"@washingtonpost/wpds-icon": "1.9.1",
"@washingtonpost/wpds-input-label": "1.9.1",
"@washingtonpost/wpds-input-shared": "1.9.1",
"@washingtonpost/wpds-theme": "1.9.1",
"@washingtonpost/wpds-visually-hidden": "1.9.1",
"@washingtonpost/wpds-button": "*",
"@washingtonpost/wpds-error-message": "*",
"@washingtonpost/wpds-helper-text": "*",
"@washingtonpost/wpds-icon": "*",
"@washingtonpost/wpds-input-label": "*",
"@washingtonpost/wpds-input-shared": "*",
"@washingtonpost/wpds-theme": "*",
"@washingtonpost/wpds-visually-hidden": "*",
"nanoid": "^3.3.4"
},
"gitHead": "37dec684cc01ef4a87df682998c91ad97368ce8a"
Expand Down
23 changes: 1 addition & 22 deletions ui/input-text/src/InputText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
unstyledInputStyles,
globalInputAutoFillTriggerAnimations,
} from "@washingtonpost/wpds-input-shared";
import { InputLabel } from "@washingtonpost/wpds-input-label";
import { ErrorMessage } from "@washingtonpost/wpds-error-message";
import { HelperText } from "@washingtonpost/wpds-helper-text";
import { VisuallyHidden } from "@washingtonpost/wpds-visually-hidden";
Expand All @@ -21,6 +20,7 @@ import {
Email,
Close,
} from "@washingtonpost/wpds-assets";
import { TextInputLabel } from "./TextInputLabel";
import { StyledContainer } from "./StyledContainer";
import type * as WPDS from "@washingtonpost/wpds-theme";

Expand All @@ -35,27 +35,6 @@ const UnstyledInput = styled("input", {
...unstyledInputStyles,
});

const TextInputLabel = styled(InputLabel, {
insetBlockStart: "0",
insetInlineStart: "$050",
position: "absolute",
pointerEvents: "none",
transform: `translateY(${theme.space["100"]})`,
transition: theme.transitions.allFast,
"@reducedMotion": {
transition: "none",
},
variants: {
isFloating: {
true: {
fontSize: theme.fontSizes["075"],
lineHeight: theme.lineHeights["100"],
transform: `translateY(${theme.space["050"]})`,
},
},
},
});

const IconContainer = styled("div", {
color: theme.colors.accessible,
display: "flex",
Expand Down
10 changes: 8 additions & 2 deletions ui/input-text/src/StyledContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import * as React from "react";
import { theme, styled } from "@washingtonpost/wpds-theme";
import type * as WPDS from "@washingtonpost/wpds-theme";
import { Box } from "@washingtonpost/wpds-box";

import {
sharedInputStyles,
sharedInputVariants,
FloatingLabelStyles
} from "@washingtonpost/wpds-input-shared";

const Container = styled(Box, {
import { TextInputLabel } from "./TextInputLabel";

const Container = styled("div", {
...sharedInputStyles,
alignItems: "center",
display: "flex",

"&:focus-within": {
borderColor: theme.colors.signal,

[`& ${TextInputLabel}`]: {
...FloatingLabelStyles,
},
},

variants: {
Expand Down
21 changes: 21 additions & 0 deletions ui/input-text/src/TextInputLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { styled, theme } from "@washingtonpost/wpds-theme";
import { InputLabel } from "@washingtonpost/wpds-input-label";
import { FloatingLabelStyles } from "@washingtonpost/wpds-input-shared";

export const TextInputLabel = styled(InputLabel, {
insetBlockStart: "0",
insetInlineStart: "$050",
position: "absolute",
pointerEvents: "none",
transform: `translateY(${theme.space["100"]})`,
transition: theme.transitions.allFast,
"@reducedMotion": {
transition: "none",
},

variants: {
isFloating: {
true: FloatingLabelStyles,
},
},
});
6 changes: 6 additions & 0 deletions ui/input-text/src/play.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ InputText.parameters = {
chromatic: { disableSnapshot: true },
};

export const AutoFocus = Template.bind({});

AutoFocus.args = {
autoFocus: true,
};

const SynchContainer = styled("div", {
display: "flex",
alignItems: "center",
Expand Down
12 changes: 10 additions & 2 deletions ui/input-textarea/src/InputTextarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
sharedInputVariants,
useFloating,
globalInputAutoFillTriggerAnimations,
FloatingLabelStyles,
} from "@washingtonpost/wpds-input-shared";
import { InputLabel } from "@washingtonpost/wpds-input-label";
import { ErrorMessage } from "@washingtonpost/wpds-error-message";
Expand Down Expand Up @@ -58,12 +59,19 @@ const ControlCSS = css({
display: "flex",
flexDirection: "column",
position: "relative",

"&:focus-within": {

[`& ${TextAreaLabel}`]: {
...FloatingLabelStyles,
},
},
});

export interface InputTextareaProps
extends Omit<
WPDS.VariantProps<typeof InputTextareaCSS>,
"isInvalid" | "isDisabled"
WPDS.VariantProps<typeof InputTextareaCSS>,
"isInvalid" | "isDisabled"
> {
/** Override CSS */
css?: WPDS.CSS;
Expand Down

4 comments on commit 31ae39a

@vercel
Copy link

@vercel vercel bot commented on 31ae39a Aug 8, 2023

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-vitejs-example – ./apps/vite-project

wpds-ui-kit-vitejs-example-git-main.preview.now.washingtonpost.com
wpds-ui-kit-vitejs-example.preview.now.washingtonpost.com

@vercel
Copy link

@vercel vercel bot commented on 31ae39a Aug 8, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 31ae39a Aug 8, 2023

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-git-main.preview.now.washingtonpost.com
wpds-ui-kit.preview.now.washingtonpost.com
build.washingtonpost.com

@vercel
Copy link

@vercel vercel bot commented on 31ae39a Aug 8, 2023

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.