-
Notifications
You must be signed in to change notification settings - Fork 280
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(portal): sidebar active item state #2119
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
6718d7c
to
46234a4
Compare
@@ -170,7 +173,8 @@ defmodule Web.NavigationComponents do | |||
|
|||
attr :id, :string, required: true, doc: "ID of the nav group container" | |||
attr :icon, :string, required: true | |||
# attr :navigate, :string, required: true | |||
attr :active_path, :string, required: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should call it current_path
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@@ -154,6 +156,7 @@ defmodule Web.NavigationComponents do | |||
flex items-center p-2 | |||
text-base font-medium text-gray-900 | |||
rounded-lg | |||
#{if String.starts_with?(@active_path, @navigate), do: @active_class, else: ""} | |||
hover:bg-gray-100 | |||
dark:text-white dark:hover:bg-gray-700 group]}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for state changes we should move them out of ~H
and do something like:
activity_class =
if String.starts_with?(assigns.current_path, assigns.navigate) do
assigns.active_class
end
assigns = assign(assigns, activity_class: activity_class)
And then to make classes more readable we can leverage list of strings instead of sigil (I noticed Elixir formatted makes some weird moves with it so was trying to avoid it in new code):
~H"""
... class={[
"flex items-center p-2",
"text-base font-medium text-gray-900",
"rounded-lg",
@activity_class
]}
"""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Will get this feedback applied
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we can do like Phoenix team does:
class={[
"flex items-center p-2",
"text-base font-medium text-gray-900",
"rounded-lg",
String.starts_with?(@current_path, @navigate) && @active_class,
]}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the second one might end up being cleaner because we need the particular navigate
attribute for each item inside the comprehension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@AndrewDryga fixed. |
Adds
active_path
to determine whether or not to highlight a sidebar item.Leaving as draft for now to allow @devsnaked to contribute. Edit: Will use this PR as the base for @devsnaked's upcoming changesEdit: fixes #2065