diff --git a/src/components/autosuggest-input.tsx b/src/components/autosuggest-input.tsx index b41934e7c..c24643228 100644 --- a/src/components/autosuggest-input.tsx +++ b/src/components/autosuggest-input.tsx @@ -7,7 +7,6 @@ import AutosuggestEmoji from 'soapbox/components/autosuggest-emoji'; import Icon from 'soapbox/components/icon'; import { Input, Portal } from 'soapbox/components/ui'; import AutosuggestAccount from 'soapbox/features/compose/components/autosuggest-account'; -import { isRtl } from 'soapbox/utils/rtl'; import { textAtCursorMatchesToken } from 'soapbox/utils/suggestions'; import type { Menu, MenuItem } from 'soapbox/components/dropdown-menu'; @@ -264,15 +263,9 @@ export default class AutosuggestInput extends ImmutablePureComponent @@ -291,7 +284,6 @@ export default class AutosuggestInput extends ImmutablePureComponent, 'maxL const Input = React.forwardRef( (props, ref) => { const intl = useIntl(); + const locale = useLocale(); const { type = 'text', icon, className, outerClassName, append, prepend, theme = 'normal', ...filteredProps } = props; @@ -90,10 +94,11 @@ const Input = React.forwardRef( 'text-gray-600': props.disabled, 'rounded-md bg-white dark:bg-gray-900 border-gray-400 dark:border-gray-800': theme === 'normal', 'rounded-full bg-gray-200 border-gray-200 dark:bg-gray-800 dark:border-gray-800 focus:bg-white': theme === 'search', - 'pr-7 rtl:pl-7 rtl:pr-3': isPassword || append, + 'pr-10 rtl:pl-10 rtl:pr-3': isPassword || append, 'pl-8': typeof icon !== 'undefined', 'pl-16': typeof prepend !== 'undefined', }, className)} + dir={typeof props.value === 'string' ? getTextDirection(props.value, { fallback: locale.direction }) : undefined} /> {append ? ( diff --git a/src/hooks/useLocale.ts b/src/hooks/useLocale.ts index 00416c6ad..6a8d7943c 100644 --- a/src/hooks/useLocale.ts +++ b/src/hooks/useLocale.ts @@ -2,21 +2,19 @@ import { getLocale } from 'soapbox/actions/settings'; import { useAppSelector } from './useAppSelector'; -import type { CSSProperties } from 'react'; - /** Locales which should be presented in right-to-left. */ const RTL_LOCALES = ['ar', 'ckb', 'fa', 'he']; interface UseLocaleResult { locale: string; - direction: CSSProperties['direction']; + direction: 'ltr' | 'rtl'; } /** Get valid locale from settings. */ const useLocale = (fallback = 'en'): UseLocaleResult => { const locale = useAppSelector((state) => getLocale(state, fallback)); - const direction: CSSProperties['direction'] = + const direction: 'ltr' | 'rtl' = RTL_LOCALES.includes(locale) ? 'rtl' : 'ltr'; diff --git a/src/utils/rtl.ts b/src/utils/rtl.ts index 3b9f1424f..a2313488e 100644 --- a/src/utils/rtl.ts +++ b/src/utils/rtl.ts @@ -45,7 +45,7 @@ function isRtl(text: string, confidence = 0.3): boolean { interface GetTextDirectionOpts { /** The default direction to return if the text is empty. */ - fallback?: 'ltr' | 'rtl'; + fallback?: 'ltr' | 'rtl' | undefined; /** The confidence threshold (0-1) to use when determining the direction. */ confidence?: number; }