Skip to content

Commit

Permalink
feat(focus): add mode option to change outline behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
stafyniaksacha committed Oct 19, 2023
1 parent 58c21a2 commit 511a376
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/plugins/components/focus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const defaultFocusConfig = {
style: 'dashed',
color: 'muted-300',
colorDark: 'muted-600',
mode: 'always' as 'always' | 'focus-visible',
}

export default plugin.withOptions(
Expand All @@ -23,19 +24,21 @@ export default plugin.withOptions(
'shurikenUi.focus',
) satisfies typeof defaultFocusConfig

const mode =
config.mode === 'focus-visible'
? '&:has(:focus-visible), &:focus-visible'
: '&:focus-within'

addComponents({
[`.${prefix}focus`]: {
[`@apply outline-${config.width} outline-${config.style} outline-offset-${config.offset}`]:
{},
'@apply outline-transparent': {},
'&:focus-within': {
[mode]: {
[`@apply outline-${config.color} dark:outline-${config.colorDark}`]:
{},
[`@apply outline-${config.style} ring-0`]: {},
},
'&:focus-visible': {
[`@apply outline-${config.width}`]: {},
},
},
})
}
Expand Down

0 comments on commit 511a376

Please sign in to comment.