Skip to content

Commit 255476c

Browse files
authoredSep 5, 2024
Fallback to static chevron color if theme is using variables (#167)
* Fallback to static chevron color if theme is using variables * Update changelog --------- Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
1 parent 9786ae1 commit 255476c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed
 

‎CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Fallback to static chevron color if theme is using variables ([#167](https://github.com/tailwindlabs/tailwindcss-forms/pull/167))
1113

1214
## [0.5.8] - 2024-08-28
1315

‎src/index.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ function resolveColor(color, opacityVariableName) {
1111

1212
const forms = plugin.withOptions(function (options = { strategy: undefined }) {
1313
return function ({ addBase, addComponents, theme }) {
14+
function resolveChevronColor(color, fallback) {
15+
let resolved = theme(color)
16+
17+
if (!resolved || resolved.includes('var(')) {
18+
return fallback
19+
}
20+
21+
return resolved.replace('<alpha-value>', '1')
22+
}
23+
1424
const strategy = options.strategy === undefined ? ['base', 'class'] : [options.strategy]
1525

1626
const rules = [
@@ -153,9 +163,9 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
153163
class: ['.form-select'],
154164
styles: {
155165
'background-image': `url("${svgToDataUri(
156-
`<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20"><path stroke="${resolveColor(
157-
theme('colors.gray.500', colors.gray[500]),
158-
'--tw-stroke-opacity'
166+
`<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20"><path stroke="${resolveChevronColor(
167+
'colors.gray.500',
168+
colors.gray[500]
159169
)}" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M6 8l4 4 4-4"/></svg>`
160170
)}")`,
161171
'background-position': `right ${spacing[2]} center`,

0 commit comments

Comments
 (0)
Failed to load comments.