Skip to content

Commit baa850a

Browse files
authored
Merge branch 'develop' into default-browser-fix
2 parents 0d0dd38 + ef13690 commit baa850a

File tree

4 files changed

+1630
-377
lines changed

4 files changed

+1630
-377
lines changed

app/containers/UIKit/Actions.tsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
11
import React, { useState } from 'react';
2+
import { View, StyleSheet } from 'react-native';
23
import { BlockContext } from '@rocket.chat/ui-kit';
34

45
import Button from '../Button';
56
import I18n from '../../i18n';
67
import { type IActions } from './interfaces';
78

9+
const styles = StyleSheet.create({
10+
hidden: {
11+
overflow: 'hidden',
12+
height: 0
13+
}
14+
});
15+
816
export const Actions = ({ blockId, appId, elements, parser }: IActions) => {
917
const [showMoreVisible, setShowMoreVisible] = useState(() => elements && elements.length > 5);
10-
const renderedElements = showMoreVisible ? elements?.slice(0, 5) : elements;
1118

19+
const shouldShowMore = elements && elements.length > 5;
20+
const maxVisible = 5;
21+
22+
if (!elements || !parser) {
23+
return null;
24+
}
25+
26+
// Always render all elements to maintain consistent hook calls
27+
// This ensures hooks are always called in the same order
28+
// Use View wrapper to conditionally hide elements instead of conditionally rendering
1229
return (
1330
<>
14-
<>
15-
{renderedElements
16-
? renderedElements?.map(element => parser?.renderActions({ blockId, appId, ...element }, BlockContext.ACTION, parser))
17-
: null}
18-
</>
19-
{showMoreVisible && <Button title={I18n.t('Show_more')} onPress={() => setShowMoreVisible(false)} />}
31+
{elements.map((element, index) => {
32+
const isVisible = !showMoreVisible || index < maxVisible;
33+
const component = parser.renderActions({ blockId, appId, ...element }, BlockContext.ACTION, parser);
34+
// Always render the component, but hide it with styles if needed
35+
return (
36+
<View key={element.actionId || `action-${index}`} style={!isVisible ? styles.hidden : undefined}>
37+
{component}
38+
</View>
39+
);
40+
})}
41+
{shouldShowMore && showMoreVisible && <Button title={I18n.t('Show_more')} onPress={() => setShowMoreVisible(false)} />}
2042
</>
2143
);
2244
};

app/containers/UIKit/UiKitModal.stories.tsx

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,116 @@ export const ModalActions = () =>
470470
]);
471471
ModalActions.storyName = 'Modal - Actions';
472472

473+
export const ModalActionsWithShowMore = () =>
474+
UiKitModal([
475+
{
476+
type: 'section',
477+
text: {
478+
type: 'mrkdwn',
479+
text: '*Actions with Show More* 🚀\n\nThis modal demonstrates the "Show more" functionality. The actions block has 8 buttons, but only the first 5 are visible initially. Click "Show more" to reveal all buttons.'
480+
}
481+
},
482+
{
483+
type: 'divider'
484+
},
485+
{
486+
type: 'actions',
487+
blockId: 'actions-show-more',
488+
elements: [
489+
{
490+
type: 'button',
491+
text: {
492+
type: 'plain_text',
493+
text: 'Primary Action',
494+
emoji: false
495+
},
496+
style: 'primary',
497+
actionId: 'action_1',
498+
value: 'action1'
499+
},
500+
{
501+
type: 'button',
502+
text: {
503+
type: 'plain_text',
504+
text: 'Secondary',
505+
emoji: false
506+
},
507+
actionId: 'action_2',
508+
value: 'action2'
509+
},
510+
{
511+
type: 'button',
512+
text: {
513+
type: 'plain_text',
514+
text: 'Danger Action',
515+
emoji: false
516+
},
517+
style: 'danger',
518+
actionId: 'action_3',
519+
value: 'action3'
520+
},
521+
{
522+
type: 'button',
523+
text: {
524+
type: 'plain_text',
525+
text: 'Button 4',
526+
emoji: false
527+
},
528+
actionId: 'action_4',
529+
value: 'action4'
530+
},
531+
{
532+
type: 'button',
533+
text: {
534+
type: 'plain_text',
535+
text: 'Button 5',
536+
emoji: false
537+
},
538+
actionId: 'action_5',
539+
value: 'action5'
540+
},
541+
{
542+
type: 'button',
543+
text: {
544+
type: 'plain_text',
545+
text: 'Button 6 - Hidden',
546+
emoji: false
547+
},
548+
actionId: 'action_6',
549+
value: 'action6'
550+
},
551+
{
552+
type: 'button',
553+
text: {
554+
type: 'plain_text',
555+
text: 'Button 7 - Hidden',
556+
emoji: false
557+
},
558+
actionId: 'action_7',
559+
value: 'action7'
560+
},
561+
{
562+
type: 'button',
563+
text: {
564+
type: 'plain_text',
565+
text: 'Button 8 - Hidden',
566+
emoji: false
567+
},
568+
actionId: 'action_8',
569+
value: 'action8'
570+
}
571+
]
572+
},
573+
{
574+
type: 'section',
575+
text: {
576+
type: 'mrkdwn',
577+
text: 'This actions block has *8 buttons* but only shows *5* initially. Click "Show more" to see all buttons!'
578+
}
579+
}
580+
]);
581+
ModalActionsWithShowMore.storyName = 'Modal - Actions with Show More';
582+
473583
export const ModalContextsDividers = () =>
474584
UiKitModal([
475585
{

0 commit comments

Comments
 (0)