Skip to content

Commit b618205

Browse files
authored
Merge pull request #4855 from GeekyAnts/fix/Input-outline
fix: input shift on focus
2 parents cbfaf2b + 6cd8568 commit b618205

File tree

4 files changed

+91
-38
lines changed

4 files changed

+91
-38
lines changed

src/components/primitives/Input/Input.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ const Input = (
112112
}
113113

114114
return (
115-
<Stack {..._stack} {...layoutProps} ref={mergeRefs([_ref, wrapperRef])}>
115+
<Stack
116+
{..._stack}
117+
{...layoutProps}
118+
ref={mergeRefs([_ref, wrapperRef])}
119+
isFocused={isFocused}
120+
>
116121
{InputLeftElement || leftElement ? InputLeftElement || leftElement : null}
117122
<StyledInput
118123
{...inputProps}

src/components/primitives/Stack/Stack.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ export interface InterfaceStackProps extends InterfaceBoxProps<IStackProps> {
2828
direction?: ResponsiveValue<
2929
'column' | 'row' | 'column-reverse' | 'row-reverse'
3030
>;
31+
/**
32+
* If true, the Stack will be in hovered state.
33+
*/
34+
isHovered?: boolean;
35+
/**
36+
* If true, the Stack will be focused.
37+
*/
38+
isFocused?: boolean;
39+
/**
40+
* If true, the Stack will be disabled.
41+
*/
42+
isDisabled?: boolean;
43+
/**
44+
* If true, the Stack will be invalid.
45+
*/
46+
isInvalid?: boolean;
47+
/**
48+
* If true, prevents the value of the children from being edited. Used with FormControls.
49+
*/
50+
isReadOnly?: boolean;
3151
}
3252

3353
export type IStackProps = InterfaceStackProps | CustomProps<'Stack'>;
@@ -44,7 +64,13 @@ const Stack = ({ space, ...props }: IStackProps, ref?: any) => {
4464
}: any = usePropsResolution(
4565
'Stack',
4666
{ ...props, size: space },
47-
{},
67+
{
68+
isDisabled: props.isDisabled,
69+
isHovered: props.isHovered,
70+
isFocused: props.isFocused,
71+
isInvalid: props.isInvalid,
72+
isReadOnly: props.isReadOnly,
73+
},
4874
{ resolveResponsively: ['space', 'direction'] }
4975
);
5076

src/theme/components/icon-button.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ import { mode } from './../tools';
22

33
const baseStyle = (props: any) => {
44
const { colorScheme } = props;
5+
const colors = props.theme.colors;
56
const focusRing = mode(
67
{
7-
boxShadow: `${colorScheme[400]} 0px 0px 0px 2px`,
8+
outlineWidth: '2px',
9+
outlineColor: `${colors[colorScheme][600]}`,
10+
outlineStyle: 'solid',
811
},
912
{
10-
boxShadow: `${colorScheme[500]} 0px 0px 0px 2px`,
13+
outlineWidth: '2px',
14+
outlineColor: `${colors[colorScheme][500]}`,
15+
outlineStyle: 'solid',
1116
}
1217
)(props);
1318

@@ -30,9 +35,7 @@ const baseStyle = (props: any) => {
3035
borderColor: `${colorScheme}.400`,
3136
},
3237
_focusVisible: {
33-
borderWidth: 2,
3438
_web: {
35-
outlineWidth: '0',
3639
style: { ...focusRing },
3740
},
3841
},

src/theme/components/input.ts

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
import { transparentize } from '../tools';
2-
3-
const baseStyle = () => {
4-
// const { primary } = props.theme.colors;
5-
// Todo: Resolve boxShadow Color or Provide some alternatiove prop for user to change focusRing color
6-
// // Todo: Update to support similar focusRing on iOS , Android and Web
7-
// const focusRing =
8-
// Platform.OS === 'web'
9-
// ? {
10-
// boxShadow:
11-
// props.variant !== 'underlined'
12-
// ? `${primary[400]} 0px 0px 0px 1px`
13-
// : `${primary[400]} 0px 1px 0px 0px`,
14-
// zIndex: 1,
15-
// }
16-
// : {
17-
// // boxShadow: `${useToken('colors', ['primary.400'])} 0px 0px 0px 1px`,
18-
// };
1+
import { transparentize, mode } from '../tools';
192

3+
const baseStyle = (props: any) => {
4+
const { primary } = props.theme.colors;
5+
const focusRing = mode(
6+
{
7+
outlineWidth: '1px',
8+
outlineColor: `${primary[600]}`,
9+
outlineStyle: 'solid',
10+
},
11+
{
12+
outlineWidth: '1px',
13+
outlineColor: `${primary[500]}`,
14+
outlineStyle: 'solid',
15+
}
16+
)(props);
2017
return {
2118
fontFamily: 'body',
2219
py: '2',
@@ -37,12 +34,7 @@ const baseStyle = () => {
3734
style: { outline: 'none' },
3835
cursor: 'auto',
3936
},
40-
_stack: {
41-
flexDirection: 'row',
42-
alignItems: 'center',
43-
// justifyContent: 'space-between',
44-
overflow: 'hidden',
45-
},
37+
4638
_input: {
4739
bg: 'transparent',
4840
flex: 1,
@@ -72,6 +64,15 @@ const baseStyle = () => {
7264
borderColor: 'muted.300',
7365
},
7466
},
67+
_stack: {
68+
flexDirection: 'row',
69+
alignItems: 'center',
70+
// justifyContent: 'space-between',
71+
overflow: 'hidden',
72+
_focus: {
73+
style: { ...focusRing },
74+
},
75+
},
7576
},
7677
_dark: {
7778
placeholderTextColor: 'text.600',
@@ -98,6 +99,15 @@ const baseStyle = () => {
9899
borderColor: 'muted.700',
99100
},
100101
},
102+
_stack: {
103+
flexDirection: 'row',
104+
alignItems: 'center',
105+
// justifyContent: 'space-between',
106+
overflow: 'hidden',
107+
_focus: {
108+
style: { ...focusRing },
109+
},
110+
},
101111
},
102112
};
103113
};
@@ -108,7 +118,6 @@ function roundedStyle(props: Record<string, any>) {
108118
borderRadius: 'full',
109119
borderWidth: '1',
110120
_focus: {
111-
borderWidth: '2',
112121
bg: transparentize('primary.600', 0.1)(theme),
113122
},
114123
_invalid: {
@@ -121,7 +130,6 @@ function outlineStyle(props: Record<string, any>) {
121130
return {
122131
borderWidth: '1',
123132
_focus: {
124-
borderWidth: '2',
125133
bg: transparentize('primary.600', 0.1)(theme),
126134
},
127135
_invalid: {
@@ -132,10 +140,8 @@ function outlineStyle(props: Record<string, any>) {
132140
function filledStyle(props: Record<string, any>) {
133141
const { theme } = props;
134142
return {
135-
borderWidth: '0',
136-
borderColor: 'transparent',
143+
borderWidth: '1',
137144
_focus: {
138-
borderWidth: '2',
139145
bg: transparentize('primary.600', 0.1)(theme),
140146
},
141147
_hover: {
@@ -149,9 +155,11 @@ function filledStyle(props: Record<string, any>) {
149155
},
150156
_light: {
151157
bg: 'muted.100',
158+
borderColor: 'muted.100',
152159
},
153160
_dark: {
154161
bg: 'muted.800',
162+
borderColor: 'muted.800',
155163
},
156164
};
157165
}
@@ -167,16 +175,27 @@ function unstyledStyle() {
167175
_focus: {
168176
bg: 'transparent',
169177
},
178+
_stack: {
179+
_focus: {
180+
style: {
181+
outlineWidth: '0',
182+
},
183+
},
184+
},
170185
};
171186
}
172187
function underlinedStyle() {
173188
return {
174189
borderWidth: '0',
175190
pl: '0',
176191
borderBottomWidth: '1',
177-
_focus: {
178-
borderBottomWidth: '2',
179-
fontWeight: '500',
192+
_stack: {
193+
_focus: {
194+
style: {
195+
outlineWidth: '0',
196+
boxShadow: '0 1px 0 0 #0891B2',
197+
},
198+
},
180199
},
181200
_invalid: {
182201
borderBottomWidth: '2',

0 commit comments

Comments
 (0)