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 ThemeToggle component #139

Closed
wants to merge 1 commit into from
Closed

Conversation

atriple
Copy link

@atriple atriple commented Oct 4, 2023

What kind of changes does this PR include?

  • Minor fixes (broken links, typos, css, etc.)

Description

  • Fix disappearing theme button when transitioning to different page. (In demo website, try to navigate Home <-> About page)
  • Improve dark-light icons to load better by using dark modifier instead of aria-pressed attribute.

* Fix disappearing theme button when transitioning to different page.
* Improve dark-light icons to load better by using dark modifier instead of aria-pressed attribute.
@netlify
Copy link

netlify bot commented Oct 4, 2023

Deploy Preview for astro-theme-cactus ready!

Name Link
🔨 Latest commit 6538ce0
🔍 Latest deploy log https://app.netlify.com/sites/astro-theme-cactus/deploys/651d88a12caa450008edada9
😎 Deploy Preview https://deploy-preview-139--astro-theme-cactus.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@chrismwilliams
Copy link
Owner

Hi @atriple thank you for taking the time to do this and bringing it to my attention, I hadn't noticed this was happening.

The issue with the icon disappearing is an Astro bug involving persistence, and only after adding named transitions does the issue appear.

For some reason the two unrelated elements break persistence set in the Header, hence why your fix works by having to continually set const button = ... with every function invocation.

Until it's fixed, I've reverted the theme to not using View Transitions as this will trip people up in various instances, and left a message in the README to your request as a current solution.

Thanks again

@vedxp
Copy link
Contributor

vedxp commented Oct 15, 2023

Hi @atriple thank you for taking the time to do this and bringing it to my attention, I hadn't noticed this was happening.

The issue with the icon disappearing is an Astro bug involving persistence, and only after adding named transitions does the issue appear.

For some reason the two unrelated elements break persistence set in the Header, hence why your fix works by having to continually set const button = ... with every function invocation.

Until it's fixed, I've reverted the theme to not using View Transitions as this will trip people up in various instances, and left a message in the README to your request as a current solution.

Thanks again

We might use transition:persist directive on the Header component instead, for fixing the issue.

src/components/layout/Header.astro:

<header
	id="main-header"
	class="group relative mb-28 flex items-center sm:ps-[4.5rem]"
	transition:persist
>
</header>

@chrismwilliams
Copy link
Owner

Thanks, and that's what I thought but unfortunately when this issue was created, persist was included. It worked until you then added a named transition on an unrelated element.

I've since changed the Toggle to a web component and removed the inline code, but it was those inconsistencies which meant that I just removed view-transitions as a default.

@vedxp
Copy link
Contributor

vedxp commented Oct 15, 2023

Thanks, and that's what I thought but unfortunately when this issue was created, persist was included. It worked until you then added a named transition on an unrelated element.

I've since changed the Toggle to a web component and removed the inline code, but it was those inconsistencies which meant that I just removed view-transitions as a default.

In that case, the latter approach works just fine. Thanks for clearing that up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants