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

refactor: limit attribute rules to input and select elements #159

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
58 changes: 29 additions & 29 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
const rules = [
{
base: [
"[type='text']",
"input:where([type='text'])",
'input:where(:not([type]))',
"[type='email']",
"[type='url']",
"[type='password']",
"[type='number']",
"[type='date']",
"[type='datetime-local']",
"[type='month']",
"[type='search']",
"[type='tel']",
"[type='time']",
"[type='week']",
'[multiple]',
"input:where([type='email'])",
"input:where([type='url'])",
"input:where([type='password'])",
"input:where([type='number'])",
"input:where([type='date'])",
"input:where([type='datetime-local'])",
"input:where([type='month'])",
"input:where([type='search'])",
"input:where([type='tel'])",
"input:where([type='time'])",
"input:where([type='week'])",
'select:where([multiple])',
'textarea',
'select',
],
Expand Down Expand Up @@ -166,7 +166,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
},
},
{
base: ['[multiple]', '[size]:where(select:not([size="1"]))'],
base: ['select:where([multiple])', 'select:where([size]:not([size="1"]))'],
class: ['.form-select:where([size]:not([size="1"]))'],
styles: {
'background-image': 'initial',
Expand All @@ -178,7 +178,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
},
},
{
base: [`[type='checkbox']`, `[type='radio']`],
base: [`input:where([type='checkbox'])`, `input:where([type='radio'])`],
class: ['.form-checkbox', '.form-radio'],
styles: {
appearance: 'none',
Expand All @@ -202,21 +202,21 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
},
},
{
base: [`[type='checkbox']`],
base: [`input:where([type='checkbox'])`],
class: ['.form-checkbox'],
styles: {
'border-radius': borderRadius['none'],
},
},
{
base: [`[type='radio']`],
base: [`input:where([type='radio'])`],
class: ['.form-radio'],
styles: {
'border-radius': '100%',
},
},
{
base: [`[type='checkbox']:focus`, `[type='radio']:focus`],
base: [`input:where([type='checkbox']):focus`, `input:where([type='radio']):focus`],
class: ['.form-checkbox:focus', '.form-radio:focus'],
styles: {
outline: '2px solid transparent',
Expand All @@ -234,7 +234,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
},
},
{
base: [`[type='checkbox']:checked`, `[type='radio']:checked`],
base: [`input:where([type='checkbox']):checked`, `input:where([type='radio']):checked`],
class: ['.form-checkbox:checked', '.form-radio:checked'],
styles: {
'border-color': `transparent`,
Expand All @@ -245,7 +245,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
},
},
{
base: [`[type='checkbox']:checked`],
base: [`input:where([type='checkbox']):checked`],
class: ['.form-checkbox:checked'],
styles: {
'background-image': `url("${svgToDataUri(
Expand All @@ -258,7 +258,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
},
},
{
base: [`[type='radio']:checked`],
base: [`input:where([type='radio']):checked`],
class: ['.form-radio:checked'],
styles: {
'background-image': `url("${svgToDataUri(
Expand All @@ -272,10 +272,10 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
},
{
base: [
`[type='checkbox']:checked:hover`,
`[type='checkbox']:checked:focus`,
`[type='radio']:checked:hover`,
`[type='radio']:checked:focus`,
`input:where([type='checkbox']):checked:hover`,
`input:where([type='checkbox']):checked:focus`,
`input:where([type='radio']):checked:hover`,
`input:where([type='radio']):checked:focus`,
Copy link
Contributor

Choose a reason for hiding this comment

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

@adamwathan Should we put these pseudo classes inside :where(…)? I'm not sure.

],
class: [
'.form-checkbox:checked:hover',
Expand All @@ -289,7 +289,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
},
},
{
base: [`[type='checkbox']:indeterminate`],
base: [`input:where([type='checkbox']):indeterminate`],
class: ['.form-checkbox:indeterminate'],
styles: {
'background-image': `url("${svgToDataUri(
Expand All @@ -307,15 +307,15 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
},
},
{
base: [`[type='checkbox']:indeterminate:hover`, `[type='checkbox']:indeterminate:focus`],
base: [`input:where([type='checkbox']):indeterminate:hover`, `input:where([type='checkbox']):indeterminate:focus`],
class: ['.form-checkbox:indeterminate:hover', '.form-checkbox:indeterminate:focus'],
styles: {
'border-color': 'transparent',
'background-color': 'currentColor',
},
},
{
base: [`[type='file']`],
base: [`input:where([type='file'])`],
class: null,
styles: {
background: 'unset',
Expand All @@ -328,7 +328,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
},
},
{
base: [`[type='file']:focus`],
base: [`input:where([type='file']):focus`],
class: null,
styles: {
outline: [`1px solid ButtonText`, `1px auto -webkit-focus-ring-color`],
Expand Down