Skip to content

Commit f23269e

Browse files
committed
fix(ui-link): fix Link outline styles and overrides
The issue was that View's CSS specificity was higher, so it took precedence over Link's own styles. This fix increases specificity higher and adds an example to test it Fixes INSTUI-4854
1 parent baed912 commit f23269e

2 files changed

Lines changed: 75 additions & 11 deletions

File tree

packages/ui-link/src/Link/README.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@ describes: Link
1010
---
1111
type: example
1212
---
13-
<Text>The quick brown fox <Link href="https://instructure.github.io/instructure-ui/">jumps</Link> over the lazy dog.</Text>
13+
<div>
14+
<Text>The quick brown fox <Link href="https://instructure.github.io/instructure-ui/"
15+
themeOverride={{
16+
focusOutlineColor: 'pink'
17+
}}>jumps</Link> over the lazy dog.</Text>
18+
<Link color="link-inverse" href="https://instructure.github.io/instructure-ui/">jumps</Link>
19+
</div>
1420
```
1521

1622
```js
1723
---
1824
type: example
1925
---
2026
<View background="primary-inverse" as="div">
21-
<Text color="primary-inverse">The quick brown fox <Link color="link-inverse" href="https://instructure.github.io/instructure-ui/">jumps</Link> over the lazy dog.</Text>
27+
<Text color="primary-inverse">The quick brown fox <Link color="link-inverse" href="https://instructure.github.io/instructure-ui/" themeOverride={{
28+
focusInverseIconOutlineColor: 'pink'
29+
}}>jumps</Link> over the lazy dog.</Text>
2230
</View>
2331
```
2432

@@ -154,6 +162,57 @@ type: example
154162
</div>
155163
```
156164

165+
### Theme overrides
166+
167+
Examples showing how theme overrides work for Link:
168+
169+
```js
170+
---
171+
type: example
172+
---
173+
<div>
174+
<Text>The quick brown fox <Link
175+
href="https://instructure.github.io/instructure-ui/"
176+
themeOverride={{
177+
focusOutlineWidth: '0.5rem',
178+
focusOutlineStyle: 'dashed',
179+
focusOutlineBorderRadius: '0',
180+
focusOutlineColor: 'pink'
181+
}}>jumps</Link> over the lazy dog.
182+
</Text>
183+
</div>
184+
```
185+
186+
```js
187+
---
188+
type: example
189+
---
190+
<View background="primary-inverse" as="div">
191+
<Text color="primary-inverse">The quick brown fox <Link
192+
color="link-inverse"
193+
href="https://instructure.github.io/instructure-ui/"
194+
themeOverride={{
195+
focusOutlineWidth: '0.5rem',
196+
focusOutlineStyle: 'dashed',
197+
focusOutlineBorderRadius: '0',
198+
focusInverseOutlineColor: 'green'
199+
}}
200+
>jumps</Link> over the lazy dog.</Text>
201+
<br />
202+
<Text color="primary-inverse">The quick brown fox <Link
203+
color="link-inverse"
204+
href="https://instructure.github.io/instructure-ui/"
205+
renderIcon={<IconUserLine />}
206+
themeOverride={{
207+
focusOutlineWidth: '0.5rem',
208+
focusOutlineStyle: 'dashed',
209+
focusOutlineBorderRadius: '0',
210+
focusInverseIconOutlineColor: 'red'
211+
}}
212+
>jumps</Link> over the lazy dog.</Text>
213+
</View>
214+
```
215+
157216
### Guidelines
158217

159218
```js

packages/ui-link/src/Link/styles.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,8 @@ const generateStyle = (
8080
fontWeight: componentTheme.fontWeight,
8181
transition: 'outline-color 0.2s',
8282
verticalAlign: 'baseline',
83-
8483
// set up focus styles
8584
outlineColor: 'transparent',
86-
outlineWidth: componentTheme.focusOutlineWidth,
87-
outlineStyle: componentTheme.focusOutlineStyle,
88-
borderRadius: componentTheme.focusOutlineBorderRadius,
8985
outlineOffset: '0.25rem',
9086
textUnderlineOffset: componentTheme.textUnderlineOffset,
9187

@@ -96,7 +92,10 @@ const generateStyle = (
9692
alignItems: 'center'
9793
}),
9894

99-
'&:focus': {
95+
'&&&&&&:focus': {
96+
outlineWidth: componentTheme.focusOutlineWidth,
97+
outlineStyle: componentTheme.focusOutlineStyle,
98+
borderRadius: componentTheme.focusOutlineBorderRadius,
10099
outlineColor: componentTheme.focusOutlineColor
101100
},
102101
'&[aria-disabled]': {
@@ -114,7 +113,8 @@ const generateStyle = (
114113
...baseStyles,
115114
cursor: 'pointer',
116115
color: componentTheme.color,
117-
'&:focus': {
116+
// This needs stronger specificity than `View`
117+
'&&&&&:focus': {
118118
color: componentTheme.color,
119119
outlineColor: componentTheme.focusOutlineColor
120120
},
@@ -147,10 +147,15 @@ const generateStyle = (
147147

148148
const inverseStyles = {
149149
color: componentTheme.colorInverse,
150-
'&:focus': {
151-
outlineColor: componentTheme.focusInverseIconOutlineColor
150+
'&&&&&:focus': {
151+
outlineColor: componentTheme.focusInverseOutlineColor
152152
},
153-
'&:hover, &:focus, &:active': {
153+
...(renderIcon && {
154+
'&&&&&:focus': {
155+
outlineColor: componentTheme.focusInverseIconOutlineColor
156+
}
157+
}),
158+
'&:hover, &&&&&:focus, &:active': {
154159
color: componentTheme.colorInverse
155160
}
156161
}

0 commit comments

Comments
 (0)