mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 17:03:15 +00:00
fix(mobile): show stay names whole in the day card's chip strip
The stay chips in the day card's header shrank to fit beside the day pill and the weather, so a name could end after one or two letters (H..., Br...). They now keep their size and show the whole name; the strip scrolls sideways instead, with its ends fading while more waits behind them.
This commit is contained in:
@@ -508,12 +508,15 @@ function TimelineHeader({ tl, dayLabel, openLabel, weatherLabel, onOpenDay, onOp
|
||||
stayLabel: (chip: HotelChip) => string
|
||||
}) {
|
||||
const WeatherIcon = weatherIconFor(tl.weather?.main)
|
||||
const [strip, setStrip] = useState<HTMLSpanElement | null>(null)
|
||||
const stripFade = useEdgeFade(strip)
|
||||
return (
|
||||
<div className="flex items-center gap-1.5 border-b border-[color:var(--m-rowbr)] px-0.5 py-[9px]">
|
||||
{/* The one horizontal scroller inside the day pager. Nested scrolling is
|
||||
the browser's: while the chips overflow they pan first, and the pager
|
||||
takes over at their end or when they fit. */}
|
||||
<span className="flex min-w-0 items-center gap-1.5 overflow-x-auto">
|
||||
takes over at their end or when they fit. The ends fade while more
|
||||
waits behind them. */}
|
||||
<span ref={setStrip} className={`flex min-w-0 items-center gap-1.5 overflow-x-auto ${edgeFadeClass(stripFade)}`}>
|
||||
{/* The same glass controls as the edit header's: a round one when the day
|
||||
is already named above it, a pill with the day's name otherwise. */}
|
||||
<button
|
||||
@@ -532,20 +535,20 @@ function TimelineHeader({ tl, dayLabel, openLabel, weatherLabel, onOpenDay, onOp
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
{/* A stay gives way before anything else in the header does: its name ends
|
||||
in an ellipsis rather than under the edge or the weather (the chip's
|
||||
label says it whole), and the time after it stays. */}
|
||||
{/* A stay's name stands whole: two stays and the weather rarely fit a
|
||||
phone, and a name cut to a letter or two said nothing, so the strip
|
||||
scrolls instead of squeezing the chips. */}
|
||||
{tl.hotelChips.map(chip => (
|
||||
<button
|
||||
key={chip.key}
|
||||
type="button"
|
||||
onClick={() => onOpenStay(chip)}
|
||||
aria-label={stayLabel(chip)}
|
||||
className={`${GLASS_CHIP} min-w-[4.5rem] shrink gap-[5px] px-2.5`}
|
||||
className={`${GLASS_CHIP} gap-[5px] px-2.5`}
|
||||
>
|
||||
<HotelChipIcon variant={chip.variant} />
|
||||
{/* Its own direction, so a Latin name in an Arabic header is cut at its end, not its start. */}
|
||||
<span dir="auto" className="min-w-0 truncate">{chip.name}</span>
|
||||
{/* Its own direction, so a Latin name reads the right way in an Arabic header. */}
|
||||
<span dir="auto">{chip.name}</span>
|
||||
{chip.time && <span className="flex-none tabular-nums text-m-muted">{chip.time.slice(0, 5)}</span>}
|
||||
</button>
|
||||
))}
|
||||
|
||||
@@ -218,13 +218,16 @@ describe('MPlanTimeline', () => {
|
||||
weatherTemp: 17,
|
||||
})
|
||||
|
||||
// The name gives way with an ellipsis; the time after it stays, with no dot between.
|
||||
// The name stands whole, never cut to a few letters: the chip keeps its
|
||||
// size and the strip scrolls instead. The time follows with no dot between.
|
||||
const sacher = screen.getByText('Hotel Sacher')
|
||||
expect(sacher).toHaveClass('truncate', 'min-w-0')
|
||||
// In an Arabic header a Latin name keeps its own direction, so the ellipsis lands at its end.
|
||||
expect(sacher).not.toHaveClass('truncate')
|
||||
// In an Arabic header a Latin name keeps its own direction.
|
||||
expect(sacher).toHaveAttribute('dir', 'auto')
|
||||
expect(sacher.closest('button')).toHaveTextContent('Hotel Sacher11:00')
|
||||
expect(sacher.closest('button')).toHaveClass('shrink')
|
||||
expect(sacher.closest('button')).toHaveClass('flex-none')
|
||||
expect(sacher.closest('button')).not.toHaveClass('shrink')
|
||||
expect(sacher.closest('button')?.parentElement).toHaveClass('overflow-x-auto')
|
||||
expect(screen.getByText('Ryokan Kyoto').closest('button')).toHaveTextContent('Ryokan Kyoto15:00')
|
||||
expect(screen.getByText('Capsule Tokyo')).toBeInTheDocument()
|
||||
expect(screen.getByText('17°')).toBeInTheDocument()
|
||||
|
||||
Reference in New Issue
Block a user