Skip to content

Commit 45e856b

Browse files
committed
fix(ui-view,ui-file-drop,ui-buttons): make focus ring radius fit the enclosed element's radius
INSTUI-4375
1 parent b092b45 commit 45e856b

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

packages/ui-buttons/src/BaseButton/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ class BaseButton extends Component<BaseButtonProps> {
280280
tabIndex={onClick && as ? tabIndex || 0 : tabIndex}
281281
disabled={isDisabled || isReadOnly}
282282
css={isEnabled ? styles?.baseButton : null}
283+
focusRingBorderRadius={String(
284+
(styles?.content as { borderRadius?: string | number })?.borderRadius
285+
)}
283286
>
284287
<span css={styles?.content}>{this.renderChildren()}</span>
285288
</View>

packages/ui-file-drop/src/FileDrop/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
335335
margin,
336336
onDropAccepted,
337337
onDropRejected,
338+
styles,
338339
...props
339340
} = this.props
340341
const id = this.props.id || this.defaultId!
@@ -368,6 +369,10 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
368369
borderRadius="large"
369370
focusColor={focusColor}
370371
height={height}
372+
focusRingBorderRadius={String(
373+
(styles?.fileDropLayout as { borderRadius?: string | number })
374+
?.borderRadius
375+
)}
371376
>
372377
<span css={this.props.styles?.fileDropLabelContent}>
373378
<span css={this.props.styles?.fileDropLayout}>

packages/ui-view/src/View/props.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ type ViewOwnProps = {
199199
* Valid values are `auto`, `contain`, `none`.
200200
*/
201201
overscrollBehavior?: 'auto' | 'contain' | 'none'
202+
/**
203+
* Sets the radius of the focus border ring.
204+
*
205+
* For offset type, the given value is increased by the difference between the focus ring' offset and the focus ring's width.
206+
*
207+
* For inset type, the given value is decreased by the sum of the focus ring' offset and the focus ring's width.
208+
*/
209+
focusRingBorderRadius?: string
202210
}
203211

204212
type PropKeys = keyof ViewOwnProps
@@ -271,7 +279,8 @@ const propTypes: PropValidators<PropKeys> = {
271279
shouldAnimateFocus: PropTypes.bool,
272280
withVisualDebug: PropTypes.bool,
273281
dir: PropTypes.oneOf(Object.values(textDirectionContextConsumer.DIRECTION)),
274-
overscrollBehavior: PropTypes.oneOf(['auto', 'contain', 'none'])
282+
overscrollBehavior: PropTypes.oneOf(['auto', 'contain', 'none']),
283+
focusRingBorderRadius: PropTypes.string
275284
}
276285

277286
// This variable will be attached as static property on the `View` component
@@ -311,7 +320,8 @@ const allowedProps: AllowedPropKeys = [
311320
'textAlign',
312321
'width',
313322
'withFocusOutline',
314-
'withVisualDebug'
323+
'withVisualDebug',
324+
'focusRingBorderRadius'
315325
]
316326

317327
export { propTypes, allowedProps }

packages/ui-view/src/View/styles.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,17 @@ type FocusRingRadius =
185185
| 'focusRing--radiusSmall'
186186
| 'focusRing--radiusMedium'
187187
| 'focusRing--radiusLarge'
188+
| 'focusRing--radiusCustom'
188189

189-
const getFocusRingRadius = (borderRadius: ViewProps['borderRadius']) => {
190+
const getFocusRingRadius = (
191+
borderRadius: ViewProps['borderRadius'],
192+
props: ViewProps
193+
) => {
190194
const baseRadiusStyle = 'focusRing--radius'
191-
192195
const initialValue = (borderRadius || '').trim().split(' ')[0]
193-
196+
if (props.focusRingBorderRadius) {
197+
return `${baseRadiusStyle}Custom`
198+
}
194199
if (verifyUniformValues(initialValue, borderRadius)) {
195200
const capitalize = (str: string) =>
196201
`${str.charAt(0).toUpperCase()}${str.slice(1)}`
@@ -242,7 +247,8 @@ const getFocusStyles = (props: ViewProps, componentTheme: ViewTheme) => {
242247
focusPosition,
243248
position,
244249
shouldAnimateFocus,
245-
borderRadius
250+
borderRadius,
251+
focusRingBorderRadius
246252
} = props
247253
const focusOutline = getFocusOutline(props)
248254
const shouldUseBrowserFocus = typeof focusOutline === 'undefined'
@@ -269,7 +275,7 @@ const getFocusStyles = (props: ViewProps, componentTheme: ViewTheme) => {
269275
}
270276

271277
if (position === 'relative') {
272-
const focusRingRadius = getFocusRingRadius(borderRadius)
278+
const focusRingRadius = getFocusRingRadius(borderRadius, props)
273279
const focusRingVariants: PartialRecord<FocusRingRadius, string | 0> = {
274280
'focusRing--radiusInherit': 'inherit',
275281
'focusRing--radiusNone': 0
@@ -289,6 +295,9 @@ const getFocusStyles = (props: ViewProps, componentTheme: ViewTheme) => {
289295
},
290296
'focusRing--radiusLarge': {
291297
borderRadius: `calc(${componentTheme.borderRadiusLarge} + (${componentTheme.focusOutlineOffset} - ${componentTheme.focusOutlineWidth}))`
298+
},
299+
'focusRing--radiusCustom': {
300+
borderRadius: `calc(${focusRingBorderRadius} + (${componentTheme.focusOutlineOffset} - ${componentTheme.focusOutlineWidth}))`
292301
}
293302
},
294303
inset: {
@@ -300,6 +309,9 @@ const getFocusStyles = (props: ViewProps, componentTheme: ViewTheme) => {
300309
},
301310
'focusRing--radiusLarge': {
302311
borderRadius: `calc(${componentTheme.borderRadiusLarge} - (${componentTheme.focusOutlineInset} + ${componentTheme.focusOutlineWidth}))`
312+
},
313+
'focusRing--radiusCustom': {
314+
borderRadius: `calc(${focusRingBorderRadius} - (${componentTheme.focusOutlineOffset} + ${componentTheme.focusOutlineWidth}))`
303315
}
304316
}
305317
}

0 commit comments

Comments
 (0)