Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

[Question]: Nav does not update the SelectedKey before firing OnSelect #337

Closed
ghurlman opened this issue Jun 6, 2023 · 1 comment
Closed
Labels
Component: Nav 👋 needs author feedback Waiting on a response from the author ❔question Issue is a question that requires an answer, not changes to code.

Comments

@ghurlman
Copy link
Member

ghurlman commented Jun 6, 2023

Describe the bug
When clicking on a nav item, the SelectedKey property is not being updated until after the event fires. So, it always seems to be a click "behind". SelectedKey is updated properly before OnChange is fired, however.

To Reproduce
Steps to reproduce the behavior:

  1. Create an app, add the Nav control, configure the Items property
  2. Add Notify("SelectedKey: " & Self.SelectedKey to the OnSelect behavior property
  3. Run the app in preview mode, and click a nav item.
  4. Click a different nav item.

Expected behavior
A notification pops up, properly reflecting the item clicked, and then again with the second click

Actual behavior
The first notification shows a blank SelectedKey, and the second notification shows the SelectedKey for the first item clicked.

@ghurlman ghurlman added bug Something isn't working ⚠️ needs triage Has not been triaged by the team yet. labels Jun 6, 2023
@denise-msft
Copy link
Member

Thanks for reporting this @ghurlman.

Nav has been implemented in a way that is intended to bind a variable in Power Apps to the Nav.SelectedKey property. This enables a way to set a default value to display on first load state (e.g., the first item in the Nav on app load, display the current page of the app).

This can be done by:

  • Initializing varSelectedKey to the desired record (e.g., in App.OnStart): Set(varSelectedKey, First(NavItems).ItemKey);
  • Setting Nav.SelectedKey to varSelectedKey
  • Updating varSelectedKey in Nav.OnChange: Set(varSelectedKey, Self.Selected.ItemKey); Notify(varSelectedKey);

At this point, the notification should be showing you the current value of varSelectedKey.

Is this acceptable? I realize it might not reflect the way in-product components are implemented, however it is consistent with how Creator Kit controls have been implemented. If so, we can update documentation to make these steps clearer.

@denise-msft denise-msft added the 👋 needs author feedback Waiting on a response from the author label Jul 18, 2023
@denise-msft denise-msft added this to the Creator Kit - July 2023 milestone Jul 19, 2023
@denise-msft denise-msft added ❔question Issue is a question that requires an answer, not changes to code. and removed bug Something isn't working labels Jul 19, 2023
@denise-msft denise-msft changed the title [BUG]: Nav does not update the SelectedKey before firing OnSelect [Question]: Nav does not update the SelectedKey before firing OnSelect Jul 19, 2023
@denise-msft denise-msft removed the ⚠️ needs triage Has not been triaged by the team yet. label Jul 19, 2023
@microsoft microsoft locked and limited conversation to collaborators Aug 1, 2023
@denise-msft denise-msft converted this issue into discussion #377 Aug 1, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Component: Nav 👋 needs author feedback Waiting on a response from the author ❔question Issue is a question that requires an answer, not changes to code.
Projects
None yet
Development

No branches or pull requests

2 participants