Skip to content

Commit

Permalink
feat(Search): fix rtl view (#8105)
Browse files Browse the repository at this point in the history
* feat(Search): fix rtl view

* feat(Search): fix rtl view

* fix(Seach): fix prettier
  • Loading branch information
EldarMuhamethanov authored Dec 28, 2024
1 parent e249428 commit 6e9f9a9
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const SearchPlayground = (props: ComponentPlaygroundProps) => {
{
value: [undefined, 'value'],
icon: [undefined, <Icon16Add key="" />],
dir: ['ltr', 'rtl'],
},
{
value: ['value'],
Expand All @@ -38,7 +39,11 @@ export const SearchPlayground = (props: ComponentPlaygroundProps) => {
},
]}
>
{(props: SearchProps) => <Search style={{ maxWidth: '320px' }} {...props} />}
{({ dir, ...props }: SearchProps) => (
<div dir={dir}>
<Search style={{ maxWidth: '320px' }} {...props} />
</div>
)}
</ComponentPlayground>
);
};
Expand Down
16 changes: 14 additions & 2 deletions packages/vkui/src/components/Search/Search.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
-webkit-tap-highlight-color: transparent;

--vkui_internal--search_height: var(--vkui--size_search_height--regular);
--vkui_internal--search_shift_direction: 1;
}

.rtl {
--vkui_internal--search_shift_direction: -1;
}

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

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

.hasIcon .controls {
/* Исключаем параметр icon из расчёта, чтобы он оставался видимым */
transform: translate3d(calc(100% - var(--vkui_internal--search_icon_size)), 0, 0);
transform: translate3d(
calc(
var(--vkui_internal--search_shift_direction) *
calc(100% - var(--vkui_internal--search_icon_size))
),
0,
0
);
}

.hasValue .controls {
Expand Down
7 changes: 6 additions & 1 deletion packages/vkui/src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { classNames, hasReactNode, noop } from '@vkontakte/vkjs';
import { useAdaptivity } from '../../hooks/useAdaptivity';
import { useAdaptivityConditionalRender } from '../../hooks/useAdaptivityConditionalRender';
import { useBooleanState } from '../../hooks/useBooleanState';
import { useDirection } from '../../hooks/useDirection';
import { useExternRef } from '../../hooks/useExternRef';
import { useNativeFormResetListener } from '../../hooks/useNativeFormResetListener';
import { usePlatform } from '../../hooks/usePlatform';
Expand Down Expand Up @@ -75,6 +76,9 @@ export const Search = ({
onFindButtonClick,
...inputProps
}: SearchProps): React.ReactNode => {
const [directionRef, textDirection = 'ltr'] = useDirection<HTMLDivElement>();
const isRtl = textDirection === 'rtl';
const rootRef = useExternRef(directionRef, getRootRef);
const inputRef = useExternRef(getRef);
const {
value: isFocused,
Expand Down Expand Up @@ -172,9 +176,10 @@ export const Search = ({
iconProp && styles.hasIcon,
inputProps.disabled && styles.disabled,
!noPadding && styles.withPadding,
isRtl && styles.rtl,
className,
)}
ref={getRootRef}
ref={rootRef}
style={style}
>
<div className={styles.field}>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6e9f9a9

Please sign in to comment.