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

fix(datetime): timepicker popover will position relative to click target #24616

Merged
merged 2 commits into from
Jan 25, 2022

Conversation

sean-perkins
Copy link
Contributor

@sean-perkins sean-perkins commented Jan 20, 2022

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

The popover positioning within datetime can result in the popover element being placed outside of the trigger/click target. Additionally, rapidly opening the timepicker within the datetime, can result in the timepicker not scrolling to the correct time.

Issue Number: #24531, #24415

What is the new behavior?

  • Presenting the popover within datetime will use the internal API for ionShadowTarget to consistently position the popover when the click target/trigger is within a shadow DOM.
  • Rapidly toggling the timepicker popover will consistently scroll the picker columns to the correct time.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Extension of #24535 (will close in favor of this, if accepted).

Popover positioning

Before After
Kapture.2022-01-20.at.15.51.48.mp4
Kapture.2022-01-20.at.15.52.58.mp4

Timepicker columns (combined with above fix)

Before After
Kapture.2022-01-20.at.15.48.47.mp4
Kapture.2022-01-20.at.15.46.17.mp4

@sean-perkins sean-perkins requested a review from a team as a code owner January 20, 2022 20:53
@github-actions github-actions bot added the package: core @ionic/core package label Jan 20, 2022
this.isTimePopoverOpen = true;
popoverRef.present(ev);

popoverRef.present(new CustomEvent('ionShadowTarget', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we extend ev instead of overwriting it completely? Similar to what ion-select does here: https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/select/select.tsx#L336

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After navigating what was used of the event object in the present function, it appeared to only use the event target or the shadow target (if set).

Was mainly following the feedback here: #24535 (comment)

I could see merging the objects on the chance that we need additional properties in the future 🤔

Comment on lines 1378 to 1380
const cols = (ev.target! as HTMLElement).querySelectorAll('ion-picker-column-internal');
cols.forEach(col => col.scrollActiveItemIntoView());
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming this can be removed if we figure out a way to remove the IOs completely, it might be worth adding a note about that somewhere. (Tech debt comment?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this should replace the IO behavior, but believe further discovery is needed to fully vet that out (created a spike for that, referencing this PR).

The picker column internal component is only used in context of the datetime and only shown within a popover, so the popover should be able to dictate all visibility-related functions with lifecycle events, instead of relying on an inner IO. I'm just unsure if picker-column-internal is intended to move to the public API for available components.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ultimately I'd like for picker-column-internal to replace the public picker-column since there are many issues with the current implementation. However, I think that is a ways off, so it should be fine to roll with this approach for now.

The only thing I'd ask is we add a TODO and make tech debt to investigate a way of having this be handled automatically. If we make this component public, I imagine users will run into this same issue.

Copy link
Contributor

@averyjohnston averyjohnston left a comment

Choose a reason for hiding this comment

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

Comments are non-blocking 👍

Copy link
Contributor

@liamdebeasi liamdebeasi left a comment

Choose a reason for hiding this comment

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

Looks good! One comment about making a tech debt ticket, but otherwise I think this is good to go. More important to have this functionality fixed than have a perfect solution that handles a use case that is still a ways off IMO.

Comment on lines 1378 to 1380
const cols = (ev.target! as HTMLElement).querySelectorAll('ion-picker-column-internal');
cols.forEach(col => col.scrollActiveItemIntoView());
Copy link
Contributor

Choose a reason for hiding this comment

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

Ultimately I'd like for picker-column-internal to replace the public picker-column since there are many issues with the current implementation. However, I think that is a ways off, so it should be fine to roll with this approach for now.

The only thing I'd ask is we add a TODO and make tech debt to investigate a way of having this be handled automatically. If we make this component public, I imagine users will run into this same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants