Skip to content

Commit

Permalink
Autoprefix the file-selector-button pseudo-element (#1412)
Browse files Browse the repository at this point in the history
* Autoprefix the file-selector-button pseudo-element

Prototype using MDN compat data where caniuse is not usable.

* Hardcode data instead of using MDN

* Add test to hacks block
  • Loading branch information
lukewarlow authored Jul 10, 2021
1 parent 05cfed6 commit 5468c9f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
19 changes: 19 additions & 0 deletions data/prefixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,25 @@ f(prefixFullscreen, { match: /x(\s#2|$)/ }, browsers =>
})
)

// File selector button
prefix(['::file-selector-button'], {
selector: true,
feature: 'fullscreen',
browsers: [
'chrome 89',
'edge 89',
'firefox 82',
'opera 75',
'safari 14.1',
'android 89',
'and_chr 89',
'op_mob 63',
'and_ff 82',
'ios_saf 14.5',
'samsung 15.0'
]
})

// Tab size
let prefixTabsize = require('caniuse-lite/data/features/css3-tabsize')

Expand Down
17 changes: 17 additions & 0 deletions lib/hacks/file-selector-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let Selector = require('../selector')

class FileSelectorButton extends Selector {
/**
* Return different selectors depend on prefix
*/
prefixed(prefix) {
if (prefix === '-webkit-') {
return '::-webkit-file-upload-button'
}
return `::file-selector-button`
}
}

FileSelectorButton.names = ['::file-selector-button']

module.exports = FileSelectorButton
2 changes: 2 additions & 0 deletions lib/prefixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let utils = require('./utils')
let hackFullscreen = require('./hacks/fullscreen')
let hackPlaceholder = require('./hacks/placeholder')
let hackPlaceholderShown = require('./hacks/placeholder-shown')
let hackFileSelectorButton = require('./hacks/file-selector-button')
let hackFlex = require('./hacks/flex')
let hackOrder = require('./hacks/order')
let hackFilter = require('./hacks/filter')
Expand Down Expand Up @@ -68,6 +69,7 @@ let hackFilterValue = require('./hacks/filter-value')
Selector.hack(hackFullscreen)
Selector.hack(hackPlaceholder)
Selector.hack(hackPlaceholderShown)
Selector.hack(hackFileSelectorButton)
Declaration.hack(hackFlex)
Declaration.hack(hackOrder)
Declaration.hack(hackFilter)
Expand Down
8 changes: 8 additions & 0 deletions test/autoprefixer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ let ffgradienter = autoprefixer({
let selectorer = autoprefixer({
overrideBrowserslist: ['Chrome 25', 'Firefox > 17', 'IE 10', 'Edge 12']
})
let fileSelectorButtoner = autoprefixer({
overrideBrowserslist: ['Chrome > 25', 'Firefox > 85']
})
let placeholderShowner = autoprefixer({
overrideBrowserslist: ['IE >= 10']
})
Expand Down Expand Up @@ -123,6 +126,8 @@ function prefixer(name: string): Plugin {
return intrinsicer
} else if (name === 'selectors' || name === 'placeholder') {
return selectorer
} else if (name === 'selectors' || name === 'file-selector-button') {
return fileSelectorButtoner
} else if (name === 'placeholder-shown') {
return placeholderShowner
} else if (name === 'backdrop-filter' || name === 'overscroll-behavior') {
Expand Down Expand Up @@ -680,6 +685,9 @@ describe('hacks', () => {
it('supports all fullscreens', () => {
check('fullscreen')
})
it('supports file-selector-button', () => {
check('file-selector-button')
})
it('supports custom prefixes', () => {
check('custom-prefix')
})
Expand Down
3 changes: 3 additions & 0 deletions test/cases/file-selector-button.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::file-selector-button {
background: black
}
6 changes: 6 additions & 0 deletions test/cases/file-selector-button.out.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
::-webkit-file-upload-button {
background: black
}
::file-selector-button {
background: black
}

0 comments on commit 5468c9f

Please sign in to comment.