daisyui icon indicating copy to clipboard operation
daisyui copied to clipboard

bug: OKLCH colors and themes not working on mobile

Open 99power opened this issue 1 year ago • 18 comments

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?)

  • Firefox 121.0
  • Chrome 120.0.6099
  • Safari 15.6 (not the latest, but should work according to the docs)

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

99power avatar Dec 27 '23 14:12 99power

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.

github-actions[bot] avatar Dec 27 '23 14:12 github-actions[bot]

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.

kriskratz avatar Dec 29 '23 03:12 kriskratz

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.

99power avatar Dec 29 '23 09:12 99power

Running on iPhone 7

What is your iOS version?

saadeghi avatar Dec 29 '23 09:12 saadeghi

iOS 15.8

99power avatar Dec 29 '23 09:12 99power

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.

ranjan-purbey avatar Jan 10 '24 06:01 ranjan-purbey

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

saadeghi avatar Jan 11 '24 03:01 saadeghi

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)

ranjan-purbey avatar Jan 11 '24 04:01 ranjan-purbey

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 avatar Jan 13 '24 20:01 sadkebab

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

sadkebab avatar Jan 13 '24 20:01 sadkebab

@sadkebab Are you also using iOS 15.8?

saadeghi avatar Jan 15 '24 12:01 saadeghi

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 avatar Jan 25 '24 06:01 ayazalam

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

ayazalam avatar Jan 25 '24 06:01 ayazalam

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

image

ruibaby avatar Feb 04 '24 02:02 ruibaby

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

image

Can you share your tailwind.config.js?

saadeghi avatar Feb 04 '24 06:02 saadeghi

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",
  ],
};

ruibaby avatar Feb 04 '24 07:02 ruibaby

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

saadeghi avatar Feb 04 '24 07:02 saadeghi

@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.

ruibaby avatar Feb 04 '24 07:02 ruibaby

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

saadeghi avatar Feb 12 '24 12:02 saadeghi

@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

ranjan-purbey avatar Feb 12 '24 12:02 ranjan-purbey

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 avatar Feb 27 '24 10:02 mctwistyup

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 avatar Feb 28 '24 10:02 mctwistyup

@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

mctwistyup avatar Feb 28 '24 17:02 mctwistyup

@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

millette avatar Feb 28 '24 20:02 millette

Any update on this?

xpluscal avatar Mar 18 '24 04:03 xpluscal

Any solution fallback for iOS 15?

Psli avatar Mar 18 '24 16:03 Psli

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

mctwistyup avatar Mar 18 '24 16:03 mctwistyup