Skip to content

Commit dedf0bb

Browse files
committed
feat(Questions): add onClick to item
1 parent c69eb85 commit dedf0bb

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/blocks/Questions/Questions.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ const QuestionsBlock = (props: QuestionsProps) => {
1616
const {title, text, additionalInfo, links, buttons, items, list} = props;
1717
const [opened, setOpened] = React.useState<number[]>([0]);
1818

19-
const toggleItem = (index: number) => {
19+
const toggleItem = (
20+
index: number,
21+
itemOnClick?: QuestionsProps['items'][number]['onClick'],
22+
) => {
2023
let newState;
2124

2225
if (opened.includes(index)) {
@@ -25,6 +28,10 @@ const QuestionsBlock = (props: QuestionsProps) => {
2528
newState = [...opened, index];
2629
}
2730

31+
if (itemOnClick) {
32+
itemOnClick(index, !opened.includes(index));
33+
}
34+
2835
setOpened(newState);
2936
};
3037

@@ -69,9 +76,18 @@ const QuestionsBlock = (props: QuestionsProps) => {
6976
</Col>
7077
<Col sizes={{all: 12, md: 8}} role={'list'}>
7178
{items.map(
72-
({title: itemTitle, text: itemText, link, listStyle = 'dash'}, index) => {
79+
(
80+
{
81+
title: itemTitle,
82+
text: itemText,
83+
link,
84+
listStyle = 'dash',
85+
onClick: itemOnClick,
86+
},
87+
index,
88+
) => {
7389
const isOpened = opened.includes(index);
74-
const onClick = () => toggleItem(index);
90+
const onClick = () => toggleItem(index, itemOnClick);
7591

7692
return (
7793
<QuestionBlockItem

src/models/constructor-items/blocks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ export interface QuestionItem {
239239
text: string;
240240
listStyle?: 'dash' | 'disk';
241241
link?: LinkProps;
242+
onClick?: (index: number, newState: boolean) => void;
242243
}
243244

244245
export interface QuestionsProps

0 commit comments

Comments
 (0)