Skip to content

Commit faf7d90

Browse files
authored
fix: NFT Grid tooltip (#31625)
## **Description** Adds tooltip to truncated NFT Grid titles. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/31625?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** Hover over NFT grid item that is truncated, if truncated it should tooltip, if the title is fully visible it should not tooltip ## **Screenshots/Recordings** https://github.com/user-attachments/assets/ea98bb55-1325-4c83-ba17-a830318f3ecf ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent 703ed49 commit faf7d90

File tree

5 files changed

+41
-36
lines changed

5 files changed

+41
-36
lines changed

ui/components/app/assets/nfts/nft-details/__snapshots__/nft-details.test.js.snap

-6
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ exports[`NFT Details should match minimal props and state snapshot 1`] = `
8080
</div>
8181
</div>
8282
</button>
83-
<p
84-
class="mm-box mm-text mm-text--body-sm mm-text--ellipsis mm-box--color-text-default"
85-
/>
86-
<p
87-
class="mm-box mm-text mm-text--body-sm mm-text--ellipsis mm-box--color-text-alternative"
88-
/>
8983
</div>
9084
</div>
9185
</div>

ui/components/app/assets/nfts/nft-details/__snapshots__/nft-full-image.test.js.snap

-8
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,6 @@ exports[`NFT full image should match snapshot 1`] = `
8181
</div>
8282
</div>
8383
</button>
84-
<p
85-
class="mm-box mm-text mm-text--body-sm mm-text--ellipsis mm-box--color-text-default"
86-
/>
87-
<p
88-
class="mm-box mm-text mm-text--body-sm mm-text--ellipsis mm-box--color-text-alternative"
89-
>
90-
Punk #4
91-
</p>
9284
</div>
9385
</div>
9486
</div>

ui/components/multichain/nft-item/nft-item.tsx

+41-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import {
2727
getTestNetworkBackgroundColor,
2828
} from '../../../selectors';
2929
import { NFT } from '../asset-picker-amount/asset-picker-modal/types';
30+
import Tooltip from '../../ui/tooltip/tooltip';
31+
import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../../shared/constants/app';
32+
// eslint-disable-next-line import/no-restricted-paths
33+
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
3034

3135
type NftItemProps = {
3236
nft?: NFT;
@@ -104,6 +108,15 @@ export const NftItem = ({
104108
/>
105109
);
106110

111+
const environmentType = getEnvironmentType();
112+
const maxStrLen = environmentType === ENVIRONMENT_TYPE_FULLSCREEN ? 40 : 20;
113+
114+
const isLongName = nft?.name && nft.name.length > maxStrLen;
115+
const isLongCollection =
116+
nft?.collection?.name &&
117+
typeof nft?.collection?.name === 'string' &&
118+
nft.collection.name.length > maxStrLen;
119+
107120
return (
108121
<Box className="nft-item__card">
109122
<Box
@@ -136,16 +149,34 @@ export const NftItem = ({
136149
{nftImageComponentToRender}
137150
</BadgeWrapper>
138151
</Box>
139-
<Text variant={TextVariant.bodySm} color={TextColor.textDefault} ellipsis>
140-
{nft?.name}
141-
</Text>
142-
<Text
143-
variant={TextVariant.bodySm}
144-
color={TextColor.textAlternative}
145-
ellipsis
146-
>
147-
{nft?.collection?.name || name}
148-
</Text>
152+
{nft && (
153+
<Tooltip
154+
position="bottom"
155+
html={
156+
<>
157+
<span>{nft?.name}</span>
158+
<br />
159+
<span>{nft?.collection?.name || name}</span>
160+
</>
161+
}
162+
disabled={!isLongName && !isLongCollection}
163+
>
164+
<Text
165+
variant={TextVariant.bodySm}
166+
color={TextColor.textDefault}
167+
ellipsis
168+
>
169+
{nft?.name}
170+
</Text>
171+
<Text
172+
variant={TextVariant.bodySm}
173+
color={TextColor.textAlternative}
174+
ellipsis
175+
>
176+
{nft?.collection?.name || name}
177+
</Text>
178+
</Tooltip>
179+
)}
149180
</Box>
150181
);
151182
};

ui/pages/confirmations/components/confirm/info/nft-token-transfer/__snapshots__/nft-token-transfer.test.tsx.snap

-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ exports[`NFTTokenTransferInfo renders correctly 1`] = `
3737
</div>
3838
</div>
3939
</button>
40-
<p
41-
class="mm-box mm-text mm-text--body-sm mm-text--ellipsis mm-box--color-text-default"
42-
/>
43-
<p
44-
class="mm-box mm-text mm-text--body-sm mm-text--ellipsis mm-box--color-text-alternative"
45-
/>
4640
</div>
4741
</div>
4842
<h2

ui/pages/confirmations/components/confirm/info/shared/nft-send-heading/__snapshots__/nft-send-heading.test.tsx.snap

-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ exports[`<NFTSendHeading /> renders component 1`] = `
3737
</div>
3838
</div>
3939
</button>
40-
<p
41-
class="mm-box mm-text mm-text--body-sm mm-text--ellipsis mm-box--color-text-default"
42-
/>
43-
<p
44-
class="mm-box mm-text mm-text--body-sm mm-text--ellipsis mm-box--color-text-alternative"
45-
/>
4640
</div>
4741
</div>
4842
<h2

0 commit comments

Comments
 (0)