Skip to content

Commit

Permalink
fix(routes/show): style "where to buy" alt text
Browse files Browse the repository at this point in the history
This patch fixes an issue where the "where to buy" button images were
preventing users from scrolling the show page when the image failed to
load and the `alt` text was shown. Now, if the image fails to load or if
there isn't a valid `avatar` to load, the button simply looks like a
text outlined button.
  • Loading branch information
nicholaschiang committed Jul 23, 2023
1 parent 89f2d47 commit 9d94e20
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
6 changes: 0 additions & 6 deletions app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
-moz-text-size-adjust: none;
}

/* hide image alt text; see https://stackoverflow.com/a/37192970 */
img[alt]:after {
@apply absolute inset-0 flex h-full w-full items-center justify-center bg-inherit text-center text-xs;
content: attr(alt);
}

/* hide outline on focus */
:focus {
outline: none;
Expand Down
38 changes: 27 additions & 11 deletions app/routes/shows.$showId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,11 @@ function WhereToBuy() {
<ul className='mt-2 flex gap-2'>
{links.map((link) => (
<li key={link.id}>
<a
href={link.url}
target='_blank'
rel='noopener noreferrer'
className={cn(buttonVariants({ variant: 'outline' }), 'h-auto')}
>
<img
src={(link.brand ?? link.retailer)?.avatar ?? ''}
alt={(link.brand ?? link.retailer ?? show).name}
/>
</a>
<BuyLink
avatar={(link.brand ?? link.retailer)?.avatar}
alt={(link.brand ?? link.retailer ?? show)?.name}
url={link.url}
/>
</li>
))}
</ul>
Expand All @@ -215,6 +209,28 @@ function WhereToBuy() {
)
}

function BuyLink({
avatar,
alt,
url,
}: {
avatar?: string | null
alt: string
url: string
}) {
return (
<a
href={url}
target='_blank'
rel='noopener noreferrer'
className={cn(buttonVariants({ variant: 'outline' }), 'h-auto')}
>
{avatar != null && <img src={avatar} alt={alt} />}
{avatar == null && alt}
</a>
)
}

function ShowInfo() {
const show = useLoaderData<typeof loader>()
return (
Expand Down

0 comments on commit 9d94e20

Please sign in to comment.