Skip to content

Commit

Permalink
[ui] Repair box-shadow on TextInput and TextArea (#23472)
Browse files Browse the repository at this point in the history
## Summary & Motivation

Repair some slightly incorrect box-shadow values on `TextInput` and
`TextArea`.

- The styled text input should have an inset box-shadow, but we appear
to have overlooked this at some point. Fixing this allows the input and
button controls to have the same default height, thus repairing the bug
that brought this to our attention.
- Note that this effectively takes the `TextInput` height down from 34px
to 32px, which may be noticeable in some parts of the app. It's more
correct and consistent, but if there are places where we're depending on
the incorrect height for alignment etc, we might notice some knock-on
effects that we should clean up.
- I also reduced the focus ring box-shadow to 2px, again to match
`Button`.
- The `TextArea` component has been ignoring its `strokeColor` prop, so
all textareas are getting the default box-shadow color. This is fixed.
- The `TextArea` now also gets a 2px focus ring.

## How I Tested These Changes

Storybook examples.
  • Loading branch information
hellendag authored Aug 7, 2024
1 parent 21f10ae commit 979d7fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const TextInputStyles = css`
line-height: 20px;
padding: 6px 6px 6px 12px;
margin: 0;
transition: box-shadow linear 150ms;
transition: box-shadow 150ms;
::placeholder {
color: ${Colors.textLighter()};
Expand All @@ -118,7 +118,7 @@ export const TextInputStyles = css`
box-shadow:
${Colors.borderDefault()} inset 0px 0px 0px 1px,
${Colors.keylineDefault()} inset 2px 2px 1.5px,
${Colors.focusRing()} 0 0 0 3px;
${Colors.focusRing()} 0 0 0 2px;
outline: none;
}
`;
Expand All @@ -141,17 +141,17 @@ const StyledInput = styled.input<StyledInputProps>`
`
: null}
box-shadow: ${({$strokeColor}) => $strokeColor || Colors.borderDefault()} 0px 0px 0px 1px;
box-shadow: ${({$strokeColor}) => $strokeColor || Colors.borderDefault()} inset 0px 0px 0px 1px;
padding: ${({$hasIcon}) => ($hasIcon ? '6px 6px 6px 28px' : '6px 6px 6px 12px')};
:hover {
box-shadow: ${({$strokeColor}) => $strokeColor || Colors.borderHover()} 0px 0px 0px 1px;
box-shadow: ${({$strokeColor}) => $strokeColor || Colors.borderHover()} inset 0px 0px 0px 1px;
}
:focus {
box-shadow:
${({$strokeColor}) => $strokeColor || Colors.borderDefault()} 0px 0px 0px 1px,
${Colors.focusRing()} 0 0 0 3px;
${({$strokeColor}) => $strokeColor || Colors.borderHover()} inset 0px 0px 0px 1px,
${Colors.focusRing()} 0 0 0 2px;
background-color: ${Colors.backgroundDefaultHover()};
}
`;
Expand All @@ -164,17 +164,16 @@ interface TextAreaProps {
export const TextArea = styled.textarea<TextAreaProps>`
${TextInputStyles}
box-shadow: ${Colors.borderDefault()} inset 0px 0px 0px 1px;
box-shadow: ${({$strokeColor}) => $strokeColor || Colors.borderDefault()} inset 0px 0px 0px 1px;
:hover {
box-shadow: ${Colors.borderHover()} inset 0px 0px 0px 1px;
box-shadow: ${({$strokeColor}) => $strokeColor || Colors.borderHover()} inset 0px 0px 0px 1px;
}
:hover {
box-shadow: ${Colors.borderHover()} inset 0px 0px 0px 1px;
}
:focus {
box-shadow: ${Colors.focusRing()} 0px 0px 0px 1px;
box-shadow:
${({$strokeColor}) => $strokeColor || Colors.borderHover()} inset 0px 0px 0px 1px,
${Colors.focusRing()} 0px 0px 0px 2px;
background-color: ${Colors.backgroundDefaultHover()};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {Meta} from '@storybook/react';
import {useState} from 'react';

import {Box} from '../Box';
import {Button} from '../Button';
import {Colors} from '../Color';
import {Icon} from '../Icon';
import {TextInput} from '../TextInput';
Expand Down Expand Up @@ -59,3 +61,19 @@ export const RightElement = () => {
/>
);
};

export const NextToButton = () => {
const [value, setValue] = useState('');
return (
<Box flex={{direction: 'row', gap: 8, alignItems: 'center'}}>
<TextInput
icon="layers"
placeholder="Type anything…"
value={value}
onChange={(e) => setValue(e.target.value)}
rightElement={<Icon name="info" color={Colors.accentPrimary()} />}
/>
<Button>Hello</Button>
</Box>
);
};

1 comment on commit 979d7fb

@github-actions
Copy link

Choose a reason for hiding this comment

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

Deploy preview for dagit-storybook ready!

✅ Preview
https://dagit-storybook-o17pv5w8r-elementl.vercel.app

Built with commit 979d7fb.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.