saadeghi / daisyui

🌼 🌼 🌼 🌼 🌼  The most popular, free and open-source Tailwind CSS component library
https://daisyui.com
MIT License
32.53k stars 1.25k forks source link

bug: OKLCH colors and themes not working on mobile #2703

Closed 99power closed 4 months ago

99power commented 7 months ago

What version of daisyUI are you using?

4.4.24

Which browsers are you seeing the problem on?

All browsers

Reproduction URL

https://daisyui.com/docs/themes/

Describe your issue

It seems not even the fallback colors for the "light" theme are working, only dark theme. Running on iPhone 7 (might this be phone related?)

Obviously a downgrade to 3.9.4 resolves the issue.

Personal note: While I love the much better colors, I think fallbacks should be complemented for all themes, maybe in a separate package. Not everyone updates their devices that regularly.

IMG_3566

github-actions[bot] commented 7 months ago

Thank you @99power for reporting issues. It helps daisyUI a lot 💚
I'll be working on issues one by one. I will help with this one as soon as a I find a solution.
In the meantime providing more details and reproduction links would be helpful.

kriskratz commented 7 months ago

Is your phone set to dark mode? What happens if you change the phone to light mode? This happened to me too.

I'm not sure if the website has all of the theme fallbacks defined. My generated CSS only defines Light and Dark themes by default.

99power commented 7 months ago

I see. Yeah the phone's dark mode/light mode changes the theme, so your fallback works. But why would it show me that my browser is outdated? Going forward - just my humble opinion - I think there should be a continued support for HSL for reason mentioned.

saadeghi commented 7 months ago

Running on iPhone 7

What is your iOS version?

99power commented 7 months ago

iOS 15.8

ranjan-purbey commented 6 months ago

It turns out that safari doesn't have support of numeric value for lightness oklch(0 0 0) but does support percentage value oklch(0% 0 0). This causes the @support query to fail and fallback styles from src/base/colors.css are used instead.

As a workaround, you can override these fallback custom css properties in your project with hex color values.

saadeghi commented 6 months ago

safari doesn't have support of numeric value for lightness oklch(0 0 0) but does support percentage value oklch(0% 0 0)

I didn't know that. According to MDN, Mix <percentage> and <number> syntax in parameters is supported by Safari 16.2+

I'm going to replace all percentages to numbers to avoid mixed syntax.

Thanks for digging the problem @ranjan-purbey

ranjan-purbey commented 6 months ago

On paper it does but appears to be a bug. We would need to replace number values with percentages (only for L. For C & H, numbers work fine)

sadkebab commented 6 months ago

I tried to work around this bug by overriding --fallback variables in the css but it does not work properly. Sometimes a oklch color gets opacity from another css variable, like --tw-text-opacity in the case of disabled buttons, and the fallback for that is to a variable declared in hex like this color: var(--fallback-bc, oklch(var(--bc)/var(--tw-text-opacity)));. This is not a proper way of falling back to colors when oklch is not supported, since it applies opaque colors when there should be transparency.

sadkebab commented 6 months ago

I also tried downgrading to 3.9.4 but it did not solve the issue for me. colors are still falling back on mobile and there is the same issue with opacity

saadeghi commented 6 months ago

@sadkebab Are you also using iOS 15.8?

ayazalam commented 6 months ago

so whats the solution here?

My website does not look good on safari I am using: theme controller also not working on iOS I have checked on safari and chrome

iPhone 11
iOS 16.0

is there any workaround? 3991B713-5145-4601-B405-D0BC0CD654E4

ayazalam commented 6 months ago

It turns out that safari doesn't have support of numeric value for lightness oklch(0 0 0) but does support percentage value oklch(0% 0 0). This causes the @support query to fail and fallback styles from src/base/colors.css are used instead.

As a workaround, you can override these fallback custom css properties in your project with hex color values.

hi where do I find this src/base/colors.css

ruibaby commented 6 months ago

It doesn't seem to work under Chromium 102 on Desktop.

image
saadeghi commented 6 months ago

It doesn't seem to work under Chromium 102 on Desktop.

image

Can you share your tailwind.config.js?

ruibaby commented 6 months ago

Can you share your tailwind.config.js?

/** @type {import('tailwindcss').Config} */
const { Icons } = require("tailwindcss-plugin-icons");
module.exports = {
  content: ["./templates/**/*.html", "./src/**/*.ts"],
  darkMode: "class",
  plugins: [
    require("@tailwindcss/typography"),
    require("@tailwindcss/aspect-ratio"),
    Icons(() => ({
      ri: {
        includeAll: true,
      },
      simpleIcons: {
        includeAll: true,
      },
      tabler: {
        includeAll: true,
      },
    })),
    require("daisyui"),
  ],
  daisyui: {
    themes: true,
  },
  safelist: [
    "i-ri-mail-line",
    "i-ri-wechat-2-line",
    "i-ri-qq-line",
    "i-ri-weibo-fill",
    "i-ri-zhihu-line",
    "i-ri-douban-line",
    "i-ri-bilibili-line",
    "i-ri-tiktok-line",
    "i-ri-telegram-fill",
    "i-ri-facebook-box-line",
    "i-ri-instagram-line",
    "i-ri-linkedin-box-line",
    "i-ri-twitter-line",
    "i-ri-slack-fill",
    "i-ri-discord-line",
    "i-ri-youtube-line",
    "i-ri-steam-fill",
    "i-ri-github-fill",
    "i-ri-gitlab-line",
    "i-ri-rss-fill",
    "i-simple-icons-matrix",
  ],
};
saadeghi commented 6 months ago

@ruibaby it should work. I need a reproduction repo so I can see what's going on.

ruibaby commented 6 months ago

@ruibaby it should work. I need a reproduction repo so I can see what's going on.

Repo:https://stackblitz.com/~/github.com/ruibaby/daisyui-color-issue

Video:

https://github.com/saadeghi/daisyui/assets/21301288/f455a915-2ab9-4a70-b794-3ad5ff405868

If there is any information missing, please let me know, thx.

saadeghi commented 5 months ago

@ranjan-purbey Update the browser. Chrome 102 is an old version.

ranjan-purbey commented 5 months ago

@ranjan-purbey Update the browser. Chrome 102 is an old version.

I think you meant to tag @ruibaby

Anyway, this affects iOS Safari versions before 16.4

mctwistyup commented 5 months ago

Hi all !

I can confirm that we encouters the same problem on safari desktop and mobile before 16.4 All DaisyUI component are "black and white" I can see that oklch value is not loaded on safari :

image

good version : image

bad version ; image

I will push any update i can here

mctwistyup commented 5 months ago

Here if i replace the value --p 0.75 by the value in percentage it's ok Someone know how i can force this value to be in percentage ?

image

mctwistyup commented 5 months ago

@saadeghi

It seems that the supported format for oklch by all browsers is "xx% x.xx x.xx" instead of "x.xx x.xx x.xx" the oklch() function you use from culori package return new oklch code without percentage for the first number.

What do you think if we change the function in src/theming/functions.js:

colorObjToString:function (input) { const { l, c, h } = input return `${cutNumber(l)} ${cutNumber(c)} ${cutNumber(h)} },

In

colorObjToString: function (input) { const { l, c, h } = input return `${cutNumber(l)*100+"%"} ${cutNumber(c)} ${cutNumber(h)} },

I'm not sure its the best way and need your advice before forking.

Thanks

millette commented 5 months ago

@99power Actually, you need Safari 16.2 and above in order to support that syntax (decimal numbers instead of percentages) according to https://caniuse.com/mdn-css_types_color_oklch_mixed_type_parameters

xpluscal commented 4 months ago

Any update on this?

Psli commented 4 months ago

Any solution fallback for iOS 15?

mctwistyup commented 4 months ago

@xpluscal @Psli we downgraded to 3.9.4 waiting for an update of @saadeghi everything is working from our side on this version