Skip to content

Add labelTextDirection handling in InputDecorator - #182477

Closed
Mairramer wants to merge 16 commits into
flutter:masterfrom
Mairramer:feat/unified-input-text-direction
Closed

Mairramer wants to merge 16 commits into
flutter:masterfrom
Mairramer:feat/unified-input-text-direction

Conversation

@Mairramer

@Mairramer Mairramer commented Feb 16, 2026 •

Copy link
Copy Markdown
Contributor

This PR introduces labelTextDirection property to InputDecoration.

Fixes #41324

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages c: tech-debt Technical debt, code quality, testing, etc. labels Feb 16, 2026
@Mairramer
Mairramer marked this pull request as ready for review February 16, 2026 22:11

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request effectively unifies text direction handling in InputDecorator, TextField, and TextFormField by introducing a new textDirection property on InputDecoration. This change correctly deprecates the old hintTextDirection property, promoting consistency for labelText and hintText directionality. The implementation is solid, well-supported by new tests, and includes a data-driven fix for migration. My review includes one suggestion to improve code clarity and performance.

Comment thread packages/flutter/lib/src/material/input_decorator.dart Outdated
@Mairramer
Mairramer force-pushed the feat/unified-input-text-direction branch from 872502b to 720fd08 Compare February 17, 2026 17:10
@Mairramer
Mairramer force-pushed the feat/unified-input-text-direction branch from 720fd08 to 20ac14b Compare February 23, 2026 16:52

@Renzo-Olivares Renzo-Olivares left a comment

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.

Hi @Mairramer, thank you for the contribution! I definitely agree we should try to make textDirection consistent across text field's components like input decorator. I left a small comment but the change and approach looks good to me overall.

Comment thread packages/flutter/lib/src/material/input_decorator.dart Outdated
@Mairramer
Mairramer force-pushed the feat/unified-input-text-direction branch from f135465 to c4a6c1c Compare February 26, 2026 21:29
strutStyle: widget.strutStyle,
textAlign: widget.textAlign,
textDirection: widget.textDirection,
textDirection: widget.decoration?.textDirection ?? widget.textDirection,

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 feels like it might be a breaking change if someone had has TextField.textDirection and TextField.hintTextDirection as different and then they migrate away from hintTextDirection. Previously the text field and input decorator could have a different text direction but after this change they cannot. I don't think this is a blocker since I think unifying the handling here is the right decision but definitely something to keep an eye out for.

Renzo-Olivares
Renzo-Olivares previously approved these changes Feb 27, 2026

@Renzo-Olivares Renzo-Olivares left a comment

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.

LGTM, thank you for the contribution @Mairramer!

@Mairramer
Mairramer force-pushed the feat/unified-input-text-direction branch from c4a6c1c to 5d50f75 Compare February 28, 2026 14:09
@Renzo-Olivares

Copy link
Copy Markdown
Contributor

There are some valid google testing failures I need to investigate further.

@Renzo-Olivares

Copy link
Copy Markdown
Contributor

@mdebbar Do you have any thoughts on whether a user might want to define different text directions for labels within the same component, i.e. InputDecorator in this case.

@Renzo-Olivares

Renzo-Olivares commented Mar 16, 2026 •

Copy link
Copy Markdown
Contributor

@mdebbar pointed out that in cases like phone numbers which should always follow LTR, it may be expected for the TextField and InputDecorator to have differing textDirections. This change is breaking if a user explicitly set their TextField.textDirection expecting to override the only the fields text direction, after this change the text direction between decorator and field become unified so setting the TextField.textDirection also sets the decoration textDirection.

I think we should probably keep the existing TextField behavior the same, i.e. input decoration should not inherit text direction from text field if not set.

We should keep the InputDecoration.textDirection, if a user currently has hintTextDirection set then it should take precedence over InputDecoration.textDirection. hintTextDirection should not be deprecated, i'd point to the use-case that introduced the parameter as reasoning #69534, i.e. a user may want to their hintTextDirection match the textDirection of their text field, while keeping their label text direction as rtl. Another option we could do is simply a labelTextDirection.

If we did want to continue this unification, the migration for existing users setting their TextField.textDirection explicitly but expecting their input decoration to use a different text direction would be for them to explicitly set their InputDecoration.textDirection.

If we did not want to continue with the unification but still enable users to change the text direction of their label or entire input decoration, then a InputDecoration.textDirection or InputDecoration.labelTextDirection would be appropriate. Keeping directionality in this state puts the onus on the developer to be explicit about the directionality of their text field and input decoration.

Generally it does make sense to me that setting TextField.textDirection explicitly, without explicitly setting my own InputDecoration would result in said InputDecoration having the same textDirection. I tried input on the web and this is how it behaves with regards to Input.placeholder.

I'm leaning towards not breaking existing users since their apps rely on this existing behavior. The addition of textDirection or labelTextDirection sounds reasonable as convenience. We should probably also add a section or a note to InputDecoration about its directionality implications (interactions with TextField), and how to override all of its components directionalities using Directionality. And a section to TextField.textDirection that notes it does not influence the input decoration components. What do you think?

One open question is If we introduce textDirection or labelTextDirection and later decide we want to unify the TextField and InputDecoration text direction will it be harder to do?

Other note: In the original issue, a workaround the user could have used is wrap their subtree with a Directionality widget and set RTL there.

@github-actions github-actions Bot removed a: text input Entering text in a text field or keyboard related problems c: tech-debt Technical debt, code quality, testing, etc. labels Mar 18, 2026
Comment thread packages/flutter/lib/src/material/input_decorator.dart
Comment thread packages/flutter/lib/src/material/input_decorator.dart Outdated
@Mairramer Mairramer changed the title Add textDirection handling in InputDecorator Add labelTextDirection handling in InputDecorator Mar 31, 2026
@loic-sharma loic-sharma added the CICD Run CI/CD label Mar 31, 2026

@Renzo-Olivares Renzo-Olivares left a comment

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.

Mostly LGTM just had a small comment regarding the test. Thank you for the changes @Mairramer!

decoration: InputDecoration(
hintText: hintText,
labelText: labelText,
labelTextDirection: TextDirection.rtl,

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.

I think this test should either explicitly wrap with a Directionality widget set to ltr or leave a comment regarding it being the default. Then labelTextDirection and hintTextDirection should both be set to rtl to make it clear between the default ltr direction set by Directionality and the explicit rtl direction set by the InputDecoration.

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 1, 2026

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the excellent contribution!

@loic-sharma loic-sharma added the CICD Run CI/CD label Apr 1, 2026

@Renzo-Olivares Renzo-Olivares left a comment

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.

LGTM

@dkwingsmt

Copy link
Copy Markdown
Contributor

Thanks for your contribution! This PR has reached completion, although we will not land this PR for now due to the material/cupertino code freeze (#184093). As soon as the decoupling is complete, we will post a way to migrate this PR to the new packages.

@dkwingsmt

Copy link
Copy Markdown
Contributor

In the meantime, I'll convert this PR to a draft and apply a label so that we can quickly find it when the freeze is lifted.

@dkwingsmt
dkwingsmt marked this pull request as draft April 8, 2026 20:10
@dkwingsmt dkwingsmt added the waiting for code freeze This PR is waiting for a code freeze to resolve. label Apr 8, 2026

@mdebbar mdebbar left a comment

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.

FYI: this PR looks good to me. Thanks for the contribution!

@Piinks Piinks added the Decoupling: Not ready to port yet Instructions will be provided when this is ready to move to flutter/packages. label Jun 24, 2026
@Piinks

Piinks commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

I've marked this PR as not ready to port to flutter/packages yet.
We'll provide instructions to move this change over to material_ui/cupertino_ui once ready to receive PRs. Thank you!

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 23, 2026
@github-actions

Copy link
Copy Markdown

This pull request contains changes to Material or Cupertino, which are currently frozen in this repository.

Changes should be made in material_ui and/or cupertino_ui in the flutter/packages repository.

Please refer to #188444 for instructions.

@Mairramer

Mairramer commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Ported to flutter/packages#12607.

@Mairramer Mairramer closed this Aug 23, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Sep 25, 2026
This PR introduces `labelTextDirection` property to InputDecoration.

Closes flutter/flutter#41324

Port of flutter/flutter#182477

## Pre-Review Checklist

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems Decoupling: Not ready to port yet Instructions will be provided when this is ready to move to flutter/packages. framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages waiting for code freeze This PR is waiting for a code freeze to resolve.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextField/TextFormField labelText and hintText should be right-aligned with TextDirection.rtl

6 participants