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

bug(TimepickerInput): Incorrect input behavior when component is in shadow DOM #30641

Closed
1 task
calebkish opened this issue Mar 17, 2025 · 0 comments · Fixed by #30642
Closed
1 task

bug(TimepickerInput): Incorrect input behavior when component is in shadow DOM #30641

calebkish opened this issue Mar 17, 2025 · 0 comments · Fixed by #30642
Labels
area: material/timepicker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@calebkish
Copy link
Contributor

calebkish commented Mar 17, 2025

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When the MatTimepickerInput component is within a shadow DOM, the input element's value will get formatted more often than it should, which results in unexpected behavior when typing.

The reason for this is MatTimepickerInput._hasFocus() making the assumption that the component will never be in the shadow DOM, doing a check that inject(DOCUMENT).activeElement === inject(ElementRef).nativeElement.

inject(DOCUMENT) refers to the root document, so when the MatTimepickerInput component instance is in the shadow DOM, the check that MatTimepickerInput._hasFocus() is doing will never be true.

The comparison that should actually be done is inject(ElementRef).nativeElement.getRootNode().activeElement === inject(ElementRef).nativeElement.

Reproduction

StackBlitz link: https://stackblitz.com/edit/components-issue-starter-ucheqywm?file=src%2Fmain.ts
Steps to reproduce:

  1. Focus on the input
  2. Try typing out "12:30 PM"
  3. On typing "1", nothing will be in the input.
  4. On typing "2", "2" will be in the input.
  5. On typing ":", "2:" will be in the input.
  6. On typing "3", "2:03 AM" will be in the input.
  7. On typing "0", nothing will be in the input.

Expected Behavior

The expected behavior is typing "12:30 PM", and the "12:30 PM" option being selected.

Actual Behavior

  1. Focus on the input
  2. Try typing out "12:30 PM"
  3. On typing "1", nothing will be in the input.
  4. On typing "2", "2" will be in the input.
  5. On typing ":", "2:" will be in the input.
  6. On typing "3", "2:03 AM" will be in the input.
  7. On typing "0", nothing will be in the input.

Environment

  • Angular: 19.2.2
  • CDK/Material: 19.2.3
  • Browser(s): Chrome, Firefox
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows
@calebkish calebkish added the needs triage This issue needs to be triaged by the team label Mar 17, 2025
calebkish pushed a commit to calebkish/components that referenced this issue Mar 17, 2025
…matting

Fixes an issue where the value of the input element referenced by a
TimepickerInput component inside a shadow DOM was getting formatted too
often due to `TimepickerInput._hasFocus()` assuming the component wasn't
in the shadow DOM.

Fixes angular#30641
calebkish pushed a commit to calebkish/components that referenced this issue Mar 17, 2025
Fixes an issue where the value of the input element referenced by a
TimepickerInput component inside a shadow DOM was getting formatted too
often due to `TimepickerInput._hasFocus()` assuming the component wasn't
in the shadow DOM.

Fixes angular#30641
calebkish pushed a commit to calebkish/components that referenced this issue Mar 17, 2025
Fixes an issue where the value of the input element referenced by a
TimepickerInput component inside a shadow DOM was getting formatted too
often due to `TimepickerInput._hasFocus()` assuming the component wasn't
in the shadow DOM.

Fixes angular#30641
calebkish pushed a commit to calebkish/components that referenced this issue Mar 17, 2025
Fixes an issue where the value of the input element referenced by a
TimepickerInput component inside a shadow DOM was getting formatted too
often due to `TimepickerInput._hasFocus()` assuming the component wasn't
in the shadow DOM.

Fixes angular#30641
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: material/timepicker and removed needs triage This issue needs to be triaged by the team labels Mar 19, 2025
calebkish pushed a commit to calebkish/components that referenced this issue Mar 19, 2025
Fixes an issue where the value of the input element referenced by a
TimepickerInput component inside a shadow DOM was getting formatted too
often due to `TimepickerInput._hasFocus()` assuming the component wasn't
in the shadow DOM.

Fixes angular#30641
crisbeto pushed a commit that referenced this issue Mar 19, 2025
…0642)

Fixes an issue where the value of the input element referenced by a
TimepickerInput component inside a shadow DOM was getting formatted too
often due to `TimepickerInput._hasFocus()` assuming the component wasn't
in the shadow DOM.

Fixes #30641

Co-authored-by: Caleb Kish <j69674031@gmail.com>
(cherry picked from commit ee44255)
mistrykaran91 pushed a commit to mistrykaran91/components that referenced this issue Mar 20, 2025
…gular#30642)

Fixes an issue where the value of the input element referenced by a
TimepickerInput component inside a shadow DOM was getting formatted too
often due to `TimepickerInput._hasFocus()` assuming the component wasn't
in the shadow DOM.

Fixes angular#30641

Co-authored-by: Caleb Kish <j69674031@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/timepicker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants