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 dropdowns have wrong mark color in browsers #3238

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/helpers/coolParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ const getCollaboraTheme = () => {
return loadState('richdocuments', 'theme', 'nextcloud')
}

const createDataThemeDiv = (elementType, theme) => {
const element = document.createElement(elementType)
element.setAttribute('id', 'cool-var-source-' + theme)
element.setAttribute('data-theme-' + theme, '')
document.body.appendChild(element)
return element
}
const generateCSSVarTokens = () => {
/* NC versus COOL */
const cssVarMap = {
Expand All @@ -69,13 +76,13 @@ const generateCSSVarTokens = () => {
'--border-radius-pill': '--co-border-radius-pill',
}
let str = ''
const element = document.getElementById('cool-var-source-light') ?? document.documentElement
const lightElement = createDataThemeDiv('div', 'light')
try {
for (const cssVarKey in cssVarMap) {
let cStyle = window.getComputedStyle(element).getPropertyValue(cssVarKey)
let cStyle = window.getComputedStyle(lightElement).getPropertyValue(cssVarKey)
if (!cStyle) {
// try suffix -dark instead
cStyle = window.getComputedStyle(element).getPropertyValue(cssVarKey + '-dark')
cStyle = window.getComputedStyle(lightElement).getPropertyValue(cssVarKey + '-dark')
}
if (!cStyle) continue // skip if it is not set
const varNames = cssVarMap[cssVarKey].split(':')
Expand All @@ -88,8 +95,7 @@ const generateCSSVarTokens = () => {
}

// New dark mode compatible way to hand over our Nextcloud variables in both light/dark to Collabora
const lightElement = document.getElementById('cool-var-source-light') ?? document.documentElement
const darkElement = document.getElementById('cool-var-source-dark') ?? document.documentElement
const darkElement = createDataThemeDiv('div', 'dark')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also remove those elements after extracting the values again?


const handover = [
'--color-main-background',
Expand Down Expand Up @@ -146,7 +152,9 @@ const generateCSSVarTokens = () => {
}
}
}

// cleanup theme elements after extracting property values
lightElement.remove()
darkElement.remove()
const customLogo = loadState('richdocuments', 'theming-customLogo', false)
if (customLogo) {
str += ';--nc-custom-logo=' + window.OCA?.Theming?.cacheBuster ?? 0 + ';'
Expand Down
Loading