mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 18:34:09 +00:00
fix(mobile): refine place headings and segmented tabs
Keep the category icon separately labeled beside the heading and verify both photo and plain headers. Give the five translated place tabs a full-width segmented surface with room for their count badges.
This commit is contained in:
@@ -30,11 +30,16 @@ function setup(over: Partial<Props> = {}) {
|
||||
}
|
||||
|
||||
describe('MPlaceSheetShell', () => {
|
||||
it('FE-MOB-PLACESHEETSHELL-001: the cover names the place, its category and where it is, the body follows', () => {
|
||||
it('FE-MOB-PLACESHEETSHELL-001: the sheet gives the category icon and heading separate names', () => {
|
||||
setup();
|
||||
expect(screen.getByRole('dialog', { name: 'Colosseum' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: 'Colosseum' })).toBeInTheDocument();
|
||||
expect(screen.getByText('Sights')).toBeInTheDocument();
|
||||
const icon = screen.getByRole('img', { name: 'Sights' });
|
||||
expect(
|
||||
icon.compareDocumentPosition(screen.getByRole('heading', { name: 'Colosseum' })) &
|
||||
Node.DOCUMENT_POSITION_FOLLOWING
|
||||
).toBeTruthy();
|
||||
expect(screen.queryByText('Sights')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('Piazza del Colosseo')).toBeInTheDocument();
|
||||
expect(screen.getByText('the body')).toBeInTheDocument();
|
||||
expect(document.querySelector('[role="dialog"] img')).toBeNull();
|
||||
@@ -82,7 +87,7 @@ describe('MPlaceSheetShell', () => {
|
||||
it('FE-MOB-PLACESHEETSHELL-004: without a name or a category the cover stays bare', () => {
|
||||
setup({ name: null, category: null });
|
||||
expect(screen.queryByRole('heading')).toBeNull();
|
||||
expect(screen.queryByText('Sights')).toBeNull();
|
||||
expect(screen.queryByRole('img', { name: 'Sights' })).toBeNull();
|
||||
expect(screen.queryByText('Piazza del Colosseo')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -96,22 +96,21 @@ export default function MPlaceSheetShell({
|
||||
const location =
|
||||
name && (address?.trim() || (lat != null && lng != null ? coordsText(lat, lng) : t('places.noCoordinates')));
|
||||
const coverLabel = t('collections.coverImage');
|
||||
const categoryIcon =
|
||||
category &&
|
||||
createElement(meta.icon, {
|
||||
className: 'size-4 flex-none',
|
||||
role: 'img',
|
||||
'aria-label': category.name,
|
||||
});
|
||||
const placeName = name && (
|
||||
<>
|
||||
{category &&
|
||||
createElement(meta.icon, {
|
||||
className: 'me-1.5 inline-block size-4 align-[-0.1em]',
|
||||
role: 'img',
|
||||
'aria-label': category.name,
|
||||
})}
|
||||
<bdi
|
||||
ref={(node) => {
|
||||
titleRef.current = node;
|
||||
}}
|
||||
>
|
||||
{name}
|
||||
</bdi>
|
||||
</>
|
||||
<bdi
|
||||
ref={(node) => {
|
||||
titleRef.current = node;
|
||||
}}
|
||||
>
|
||||
{name}
|
||||
</bdi>
|
||||
);
|
||||
const closeLabel = t('common.close');
|
||||
const renderPlaceHeader = () => (
|
||||
@@ -140,7 +139,12 @@ export default function MPlaceSheetShell({
|
||||
) : (
|
||||
placeName && (
|
||||
<>
|
||||
<h2 className="m-0 line-clamp-2 break-words text-title font-bold leading-tight">{placeName}</h2>
|
||||
<div className="flex items-start gap-1.5">
|
||||
{categoryIcon && <span className="mt-1.5 flex flex-none">{categoryIcon}</span>}
|
||||
<h2 className="m-0 line-clamp-2 min-w-0 break-words text-title font-bold leading-tight">
|
||||
{placeName}
|
||||
</h2>
|
||||
</div>
|
||||
<PlaceLocationBadge address={address} lat={lat} lng={lng} t={t} />
|
||||
</>
|
||||
)
|
||||
@@ -149,7 +153,8 @@ export default function MPlaceSheetShell({
|
||||
</header>
|
||||
) : (
|
||||
<FormSheetHeader
|
||||
icon={category ? undefined : meta.icon}
|
||||
icon={meta.icon}
|
||||
leading={categoryIcon}
|
||||
title={head ?? placeName}
|
||||
subtitle={
|
||||
location && (
|
||||
|
||||
@@ -14,8 +14,8 @@ import { MPlaceMediaView } from './MPlaceMediaSection';
|
||||
import { MVisitsView } from './MVisitsSection';
|
||||
|
||||
/**
|
||||
* Place sections stay in reach while the detail cards scroll. Wrapping keeps
|
||||
* the options visible without a sideways gesture on narrow screens.
|
||||
* Place sections stay in reach while the detail cards scroll. The tabs share
|
||||
* the available width and long labels can wrap on narrow screens.
|
||||
*/
|
||||
export default function MPlaceSheetTabs({
|
||||
sheet,
|
||||
@@ -32,37 +32,37 @@ export default function MPlaceSheetTabs({
|
||||
const { tab } = sheet;
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
role="tablist"
|
||||
aria-label={t('placeSheet.tabs')}
|
||||
className="sticky top-0 z-[2] -mx-1 flex flex-wrap gap-1 bg-m-sheetop px-1 py-2.5"
|
||||
>
|
||||
{PLACE_TABS.map((key) => {
|
||||
const on = tab === key;
|
||||
return (
|
||||
<button
|
||||
key={key}
|
||||
id={`${id}-${key}`}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={on}
|
||||
aria-controls={`${id}-panel`}
|
||||
onClick={() => sheet.setTab(key)}
|
||||
className={
|
||||
on
|
||||
? 'inline-flex min-h-10 max-w-full items-center gap-1 rounded-xl bg-m-act px-2.5 py-1 text-start text-caption font-semibold text-m-actfg'
|
||||
: 'inline-flex min-h-10 max-w-full items-center gap-1 rounded-xl bg-m-ic px-2.5 py-1 text-start text-caption font-semibold text-m-muted'
|
||||
}
|
||||
>
|
||||
{t(PLACE_TAB_LABEL[key])}
|
||||
{sheet.counts[key] > 0 && (
|
||||
<span className="grid h-4 min-w-4 flex-none place-items-center rounded-full bg-m-sheetop px-1 text-caption tabular-nums leading-none text-m-ink">
|
||||
{sheet.counts[key]}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
<div className="sticky top-0 z-[2] bg-m-sheetop py-2.5">
|
||||
<div
|
||||
role="tablist"
|
||||
aria-label={t('placeSheet.tabs')}
|
||||
className="grid grid-cols-5 gap-0.5 rounded-3xl bg-m-ic p-1"
|
||||
>
|
||||
{PLACE_TABS.map((key) => {
|
||||
const on = tab === key;
|
||||
return (
|
||||
<button
|
||||
key={key}
|
||||
id={`${id}-${key}`}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={on}
|
||||
aria-controls={`${id}-panel`}
|
||||
onClick={() => sheet.setTab(key)}
|
||||
className={`flex min-h-10 min-w-0 flex-wrap items-center justify-center gap-x-1 gap-y-0.5 rounded-full px-1 py-1.5 text-center text-caption font-semibold leading-tight focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-m-act ${
|
||||
on ? 'bg-m-act text-m-actfg focus-visible:outline-m-actfg' : 'text-m-muted'
|
||||
}`}
|
||||
>
|
||||
<span className="min-w-0 [overflow-wrap:anywhere]">{t(PLACE_TAB_LABEL[key])}</span>
|
||||
{sheet.counts[key] > 0 && (
|
||||
<span className="grid h-4 min-w-4 flex-none place-items-center rounded-full bg-m-sheetop px-1 text-caption tabular-nums leading-none text-m-ink">
|
||||
{sheet.counts[key]}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div id={`${id}-panel`} role="tabpanel" aria-labelledby={`${id}-${tab}`} className="flex flex-col gap-3 pt-1">
|
||||
{sheet.empty[tab] ? (
|
||||
|
||||
Reference in New Issue
Block a user