Skip to content

Commit 6e9f9a9

Browse files
feat(Search): fix rtl view (#8105)
* feat(Search): fix rtl view * feat(Search): fix rtl view * fix(Seach): fix prettier
1 parent e249428 commit 6e9f9a9

13 files changed

+46
-24
lines changed

packages/vkui/src/components/Search/Search.e2e-playground.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const SearchPlayground = (props: ComponentPlaygroundProps) => {
1818
{
1919
value: [undefined, 'value'],
2020
icon: [undefined, <Icon16Add key="" />],
21+
dir: ['ltr', 'rtl'],
2122
},
2223
{
2324
value: ['value'],
@@ -38,7 +39,11 @@ export const SearchPlayground = (props: ComponentPlaygroundProps) => {
3839
},
3940
]}
4041
>
41-
{(props: SearchProps) => <Search style={{ maxWidth: '320px' }} {...props} />}
42+
{({ dir, ...props }: SearchProps) => (
43+
<div dir={dir}>
44+
<Search style={{ maxWidth: '320px' }} {...props} />
45+
</div>
46+
)}
4247
</ComponentPlayground>
4348
);
4449
};

packages/vkui/src/components/Search/Search.module.css

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
-webkit-tap-highlight-color: transparent;
55

66
--vkui_internal--search_height: var(--vkui--size_search_height--regular);
7+
--vkui_internal--search_shift_direction: 1;
8+
}
9+
10+
.rtl {
11+
--vkui_internal--search_shift_direction: -1;
712
}
813

914
.withPadding {
@@ -130,14 +135,21 @@
130135
color: var(--vkui--color_icon_secondary);
131136
transition: transform 0.3s var(--vkui--animation_easing_platform);
132137
/* Используем translate3d, чтобы поправить дергание при наведении в Safari */
133-
transform: translate3d(100%, 0, 0);
138+
transform: translate3d(calc(var(--vkui_internal--search_shift_direction) * 100%), 0, 0);
134139

135140
--vkui_internal--search_icon_size: calc(var(--vkui_internal--search_height) + 4px);
136141
}
137142

138143
.hasIcon .controls {
139144
/* Исключаем параметр icon из расчёта, чтобы он оставался видимым */
140-
transform: translate3d(calc(100% - var(--vkui_internal--search_icon_size)), 0, 0);
145+
transform: translate3d(
146+
calc(
147+
var(--vkui_internal--search_shift_direction) *
148+
calc(100% - var(--vkui_internal--search_icon_size))
149+
),
150+
0,
151+
0
152+
);
141153
}
142154

143155
.hasValue .controls {

packages/vkui/src/components/Search/Search.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { classNames, hasReactNode, noop } from '@vkontakte/vkjs';
66
import { useAdaptivity } from '../../hooks/useAdaptivity';
77
import { useAdaptivityConditionalRender } from '../../hooks/useAdaptivityConditionalRender';
88
import { useBooleanState } from '../../hooks/useBooleanState';
9+
import { useDirection } from '../../hooks/useDirection';
910
import { useExternRef } from '../../hooks/useExternRef';
1011
import { useNativeFormResetListener } from '../../hooks/useNativeFormResetListener';
1112
import { usePlatform } from '../../hooks/usePlatform';
@@ -75,6 +76,9 @@ export const Search = ({
7576
onFindButtonClick,
7677
...inputProps
7778
}: SearchProps): React.ReactNode => {
79+
const [directionRef, textDirection = 'ltr'] = useDirection<HTMLDivElement>();
80+
const isRtl = textDirection === 'rtl';
81+
const rootRef = useExternRef(directionRef, getRootRef);
7882
const inputRef = useExternRef(getRef);
7983
const {
8084
value: isFocused,
@@ -172,9 +176,10 @@ export const Search = ({
172176
iconProp && styles.hasIcon,
173177
inputProps.disabled && styles.disabled,
174178
!noPadding && styles.withPadding,
179+
isRtl && styles.rtl,
175180
className,
176181
)}
177-
ref={getRootRef}
182+
ref={rootRef}
178183
style={style}
179184
>
180185
<div className={styles.field}>
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)