Skip to content

Commit

Permalink
Use tooltip for the Timezone only when necessary. (#56214)
Browse files Browse the repository at this point in the history
* Use tooltip for the Timezone only when necessary.

* Add changelog entry.

* Improve timezone detail check.
  • Loading branch information
afercia committed Dec 5, 2023
1 parent 96305e9 commit 743e0b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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 }`;

// 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

1 comment on commit 743e0b6

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 743e0b6.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7097643771
📝 Reported issues:

Please sign in to comment.