Skip to content

Fix : Dataviews date misalignment#75611

Open
Vrishabhsk wants to merge 2 commits intoWordPress:trunkfrom
Vrishabhsk:fix/date-misalignment
Open

Fix : Dataviews date misalignment#75611
Vrishabhsk wants to merge 2 commits intoWordPress:trunkfrom
Vrishabhsk:fix/date-misalignment

Conversation

@Vrishabhsk
Copy link
Copy Markdown
Contributor

What?

Why?

Native type="date" inputs display dates in a browser-specific format (typically yyyy-mm-dd) . Users expect to see dates formatted according to their locale settings (e.g., dd/mm/yyyy in Europe, mm/dd/yyyy in the US). This change provides:

  1. Locale-aware date display - Dates are now displayed in the user's preferred locale format
  2. Better placeholder guidance - Input fields show locale-appropriate placeholders (e.g., dd/mm/yyyy or mm/dd/yyyy)
  3. Consistent experience - Both single date picker and date range picker now share the same formatting logic

How?

Changes made:

  1. dataviews-filters/utils.ts:

    • formatDateValue(value: string) - Formats an ISO date string (yyyy-mm-dd) to a locale-aware display string using toLocaleDateString()
    • getDatePlaceholder() - Generates a locale-aware placeholder string (e.g., dd/mm/yyyy, mm/dd/yyyy) using Intl.DateTimeFormat
  2. dataform-controls/date.tsx:

    • Imported the new utility functions
    • Changed InputControl type from "date" to "text" for both single date and date range inputs
    • Added placeholder prop using getDatePlaceholder()
    • Applied formatDateValue() to display dates in the input value
  3. dataviews-filters/filter.tsx:

    • Imported formatDateValue utility
    • Applied date formatting to filter label display for active date filters
    • Handles both single date values and date range arrays

Testing Instructions

  1. Open the WordPress admin area with Gutenberg active.
  2. Navigate to any view that uses Dataviews with date filters (e.g., Posts list with date filter).
  3. Open a date filter and observe:
    • The date input fields should display a placeholder in your browser's locale format (e.g., dd/mm/yyyy for UK, mm/dd/yyyy for US).
    • Select a date using the calendar widget or type a date in the input.
    • The date should display in your locale format instead of yyyy-mm-dd.
  4. Test with a date range filter:
    • Both "From" and "To" inputs should show locale-aware placeholders.
    • Selected dates should display in locale format.
  5. Verify that filter chips/tags for date filters show the formatted date value.
Before (Russia w Date selected) After (Russia w Date selected)
Screenshot 2026-02-17 at 2 14 18 PM Screenshot 2026-02-17 at 2 13 30 PM
Before (Russia w/ Date selected) After (Russia w/ Date selected)
Screenshot 2026-02-17 at 2 14 26 PM Screenshot 2026-02-17 at 2 13 39 PM

@github-actions
Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @JanaMW27.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: JanaMW27.

Co-authored-by: Vrishabhsk <vrishabhsk@git.wordpress.org>
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

__next40pxDefaultSize
ref={ validityTargetRef }
type="date"
type="text"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This alone breaks so many things like validation, a11y etc..

Below we don't use the getValueFormatted which also breaks formatting.

Thanks for the PR, but it's not the right approach. We need to explore alternatives, although I'm not even sure how we could match a native date input (that is needed) with custom formatting we use for displaying the values..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] DataViews /packages/dataviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dates misalignment in the Date filter in DataViews

2 participants