material-components / material-components/material-components-android

[MaterialDatePicker] Support programatic mtrl_picker_* string values

Open
#3,309 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request Widget: DatePicker
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

Some applications do not use static string resources files, such as applications that receive localized values from a server. In this case overriding `mtrl_picker_*` string resource values is not a valid solution to change the UI of various components. Another use-case would be needing to add additional contextual data into these strings when shown on the UI (like in the code example below).

![Cursor_and_mobile-one_–_as_values-as_xml](https://user-images.githubusercontent.com/1331002/225754133-f8148267-c2d7-4b03-b535-3dcc89789d3b.png)

It would be nice if this library could provide a way to modify some of these string values at runtime as they are displayed on the UI. This would be especially useful for error states where additional context from the application could be useful to the user.

Something like:

```kotlin
val minDate = calcMinDate()
val maxDate = calcMaxDate()

MaterialDatePicker.Builder.datePicker()
.setSelection(...)
.setInputMode(...)
.setPickerOutOfRangeError { date ->
// alternative to setting mtrl_picker_out_of_range
"Please enter a date that is within the range of $minDate to $maxDate. $date is outside of this range"
}
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the MaterialDatePicker.Builder API and the existing mtrl_picker_* string resources; no source files or tests are named in the issue. Determine which displayed strings, especially out-of-range errors, need runtime customization and how the proposed callbacks should coexist with resource defaults. Done means applications can supply contextual string values programmatically while existing resource overrides continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.