Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tooltip for the Timezone only when necessary. #56214

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Bug Fix

- `DateTime`: Make the Timezone indication render a tooltip only when necessary. ([#56214](https://github.com/WordPress/gutenberg/pull/56214)).
- `ToolsPanelItem`: Use useLayoutEffect to prevent rendering glitch for last panel item styling. ([#56536](https://github.com/WordPress/gutenberg/pull/56536)).
- `FormTokenField`: Fix broken suggestions scrollbar when the `__experimentalExpandOnFocus` prop is defined ([#56426](https://github.com/WordPress/gutenberg/pull/56426)).
- `FormTokenField`: `onFocus` prop is now typed as a React `FocusEvent` ([#56426](https://github.com/WordPress/gutenberg/pull/56426)).
Expand Down
18 changes: 15 additions & 3 deletions packages/components/src/date-time/time/timezone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,24 @@ const TimeZone = () => {
? timezone.abbr
: `UTC${ offsetSymbol }${ timezone.offset }`;

// Replace underscore with space in strings like `America/Costa_Rica`.
const prettyTimezoneString = timezone.string.replace( '_', ' ' );

const timezoneDetail =
'UTC' === timezone.string
? __( 'Coordinated Universal Time' )
: `(${ zoneAbbr }) ${ timezone.string.replace( '_', ' ' ) }`;

return (
: `(${ zoneAbbr }) ${ prettyTimezoneString }`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: `(${ zoneAbbr }) ${ prettyTimezoneString }`;
: `(${ zoneAbbr }) ${ prettyTimezoneString }`.trim();


// When the prettyTimezoneString is empty, there is no additional timezone
// detail information to show in a Tooltip.
const hasNoAdditionalTimezoneDetail =
prettyTimezoneString.trim().length === 0;

return hasNoAdditionalTimezoneDetail ? (
<StyledComponent className="components-datetime__timezone">
{ zoneAbbr }
</StyledComponent>
) : (
<Tooltip placement="top" text={ timezoneDetail }>
<StyledComponent className="components-datetime__timezone">
{ zoneAbbr }
Expand Down
Loading