Skip to content

Commit b86616b

Browse files
authored
fix(Icons): make icon without href no clickable (#500) (#501)
1 parent a1f5b25 commit b86616b

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

src/blocks/Icons/Icons.tsx

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useContext} from 'react';
1+
import React, {Fragment, useContext} from 'react';
22

33
import {Image, Title} from '../../components';
44
import {LocationContext} from '../../context/locationContext';
@@ -9,23 +9,36 @@ import './Icons.scss';
99

1010
const b = block('icons-block');
1111

12+
const getItemContent = (item: IconsBlockProps['items'][number]) => (
13+
<Fragment>
14+
<Image className={b('image')} src={item.src} />
15+
<p className={b('text')}>{item.text}</p>
16+
</Fragment>
17+
);
18+
1219
const Icons = ({title, size = 's', items}: IconsBlockProps) => {
1320
const {hostname} = useContext(LocationContext);
1421

1522
return (
1623
<div className={b({size})}>
1724
{title && <Title className={b('header')} title={title} colSizes={{all: 12}} />}
18-
{items.map((item) => (
19-
<a
20-
className={b('item')}
21-
key={item.url}
22-
href={item.url}
23-
{...getLinkProps(item.url, hostname)}
24-
>
25-
<Image className={b('image')} src={item.src} />
26-
<p className={b('text')}>{item.text}</p>
27-
</a>
28-
))}
25+
{items.map((item) => {
26+
const itemContent = getItemContent(item);
27+
return item.url ? (
28+
<a
29+
className={b('item')}
30+
key={item.url}
31+
href={item.url}
32+
{...getLinkProps(item.url, hostname)}
33+
>
34+
{itemContent}
35+
</a>
36+
) : (
37+
<div className={b('item')} key={item.url}>
38+
{itemContent}
39+
</div>
40+
);
41+
})}
2942
</div>
3043
);
3144
};

src/blocks/Icons/__stories__/data.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"items": [
66
{
77
"src": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icons-link_1_64.svg",
8-
"text": "Lorem ipsum dolor sit amet",
9-
"url": "#"
8+
"text": "Lorem ipsum dolor sit amet"
109
},
1110
{
1211
"src": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icons-link_2_64.svg",

0 commit comments

Comments
 (0)