Skip to content

Commit 7cad521

Browse files
authored
feat: address RTL UI feedback (#1173)
Addresses https://sendbird.atlassian.net/browse/CLNP-4340 - [x] Fixed an issue : setting `htmlTextDirection` prop didn't work when using SendbirdProvider but only work in App module. - [x] The paper plane icon should point left not right - [x] The buttons in the modal footer should be positioned in the right side not left
1 parent 36d4513 commit 7cad521

File tree

9 files changed

+32
-42
lines changed

9 files changed

+32
-42
lines changed

src/hooks/VoicePlayer/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,13 @@ export const VoicePlayerProvider = ({
211211
stop,
212212
voicePlayerStore,
213213
}}>
214+
{/**
215+
* This empty div is also used for finding the root div element
216+
* within SendbirdProvider to set the 'dir' attribute ('rtl' | 'ltr').
217+
* See hooks/useHTMLTextDirection.tsx for more details.
218+
*/}
214219
<div id={VOICE_PLAYER_ROOT_ID} style={{ display: 'none' }} />
220+
215221
{children}
216222
</Context.Provider>
217223
);

src/hooks/useHTMLTextDirection.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { useEffect } from 'react';
2+
import { VOICE_PLAYER_ROOT_ID } from '../utils/consts';
3+
import { HTMLTextDirection } from '../types';
4+
5+
const useHTMLTextDirection = (direction: HTMLTextDirection) => {
6+
useEffect(() => {
7+
/**
8+
* It sets the 'dir' attribute of the closest parent <div> element of the element with VOICE_PLAYER_ROOT_ID cause:
9+
* - An empty <div> element is created in the VoiceMessageProvider, which is the highest-level <div> element within the SendbirdProvider.
10+
* - It tries to find the nearest parent <div> element within the SendbirdProvider and sets 'dir' attribute,
11+
* ensuring that the directionality is applied correctly.
12+
* */
13+
const targetElement = document.getElementById(VOICE_PLAYER_ROOT_ID);
14+
targetElement.parentElement.dir = direction;
15+
}, [direction]);
16+
};
17+
18+
export default useHTMLTextDirection;

src/lib/Sendbird.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { EmojiManager } from './emojiManager';
5555
import { uikitConfigStorage } from './utils/uikitConfigStorage';
5656
import useMessageTemplateUtils from './hooks/useMessageTemplateUtils';
5757
import { EmojiReactionListRoot, MenuRoot } from '../ui/ContextMenu';
58+
import useHTMLTextDirection from '../hooks/useHTMLTextDirection';
5859

5960
export { useSendbirdStateContext } from '../hooks/useSendbirdStateContext';
6061

@@ -285,6 +286,8 @@ const SendbirdSDK = ({
285286
};
286287
}, [currentTheme]);
287288

289+
useHTMLTextDirection(htmlTextDirection);
290+
288291
const isOnline = useOnlineStatus(sdkStore.sdk, logger);
289292

290293
const markAsReadScheduler = useMarkAsReadScheduler({ isConnected: isOnline }, { logger });

src/modules/App/AppLayout.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { MobileLayout } from './MobileLayout';
99
import useSendbirdStateContext from '../../hooks/useSendbirdStateContext';
1010
import { SendableMessageType } from '../../utils';
1111
import { getCaseResolvedReplyType } from '../../lib/utils/resolvedReplyType';
12-
import useApplyTextDirection from './hooks/useApplyTextDirection';
1312

1413
export const AppLayout = (props: AppLayoutProps) => {
1514
const {
@@ -20,7 +19,6 @@ export const AppLayout = (props: AppLayoutProps) => {
2019
currentChannel,
2120
setCurrentChannel,
2221
enableLegacyChannelModules,
23-
htmlTextDirection,
2422
} = props;
2523

2624
const globalStore = useSendbirdStateContext();
@@ -34,8 +32,6 @@ export const AppLayout = (props: AppLayoutProps) => {
3432
const [startingPoint, setStartingPoint] = useState<number | null>(null);
3533
const { isMobile } = useMediaQueryContext();
3634

37-
useApplyTextDirection(htmlTextDirection);
38-
3935
/**
4036
* Below configs can be set via Dashboard UIKit config setting but as a lower priority than App props.
4137
* So need to be have fallback value \w global configs even though each prop values are undefined

src/modules/App/hooks/useApplyTextDirection.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/modules/App/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export default function App(props: AppProps) {
157157
isReactionEnabled={isReactionEnabled}
158158
isMentionEnabled={isMentionEnabled}
159159
isVoiceMessageEnabled={isVoiceMessageEnabled}
160+
htmlTextDirection={htmlTextDirection}
160161
>
161162
<AppLayout
162163
isMessageGroupingEnabled={isMessageGroupingEnabled}
@@ -169,7 +170,6 @@ export default function App(props: AppProps) {
169170
isReactionEnabled={isReactionEnabled}
170171
replyType={replyType}
171172
showSearchIcon={showSearchIcon}
172-
htmlTextDirection={htmlTextDirection}
173173
/>
174174
</Sendbird>
175175
);

src/modules/ChannelSettings/components/ChannelSettingsUI/channel-settings-ui.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@
8686
}
8787
.sendbird-channel-settings__panel-icon-right {
8888
right: 16px;
89-
/*rtl:raw:
90-
transform: rotate(180deg);*/
9189
}
9290
.sendbird-channel-settings__panel-icon--open {
9391
transform: rotate(90deg) /*rtl:rotate(270deg)*/;

src/ui/MessageInput/index.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
padding: 6px;
8080
right: 16px;
8181
bottom: 14px;
82+
/*rtl:raw:
83+
transform: rotate(180deg);*/
8284
}
8385

8486
.sendbird-message-input--attach-input {

src/ui/Modal/index.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
display: flex;
5858
flex-direction: row;
5959
justify-content: flex-end;
60+
/*rtl:raw:
61+
justify-content: flex-start;*/
6062
@include mobile() {
6163
position: sticky;
6264
bottom: 24px;

0 commit comments

Comments
 (0)