Skip to content

Commit f84f495

Browse files
committed
fix(ui-view,ui-position,ui-popover): fix 'stretch' placement in Popover/ContextView
This was actually never working properly. Now the popover is in the right position and is stretched when above/below the target. Its not stretched when its to the left/right INSTUI-4653
1 parent 90747ec commit f84f495

File tree

6 files changed

+37
-9
lines changed

6 files changed

+37
-9
lines changed

packages/ui-drilldown/src/Drilldown/index.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,8 @@ class Drilldown extends Component<DrilldownProps, DrilldownState> {
13671367
maxWidth,
13681368
role,
13691369
as,
1370-
label
1370+
label,
1371+
trigger
13711372
} = this.props
13721373

13731374
if (!this.currentPage) {
@@ -1405,7 +1406,9 @@ class Drilldown extends Component<DrilldownProps, DrilldownState> {
14051406
getDisabledOptionProps
14061407
}) => (
14071408
<View
1408-
borderWidth="small"
1409+
// if there is a trigger the border needs to be rendered by the <Popover>
1410+
// (because it has an arrow)
1411+
{...(trigger ? {} : { borderWidth: 'small' })}
14091412
as="div"
14101413
elementRef={this.handleDrilldownRef}
14111414
tabIndex={0}
@@ -1496,11 +1499,17 @@ class Drilldown extends Component<DrilldownProps, DrilldownState> {
14961499
onMouseOver,
14971500
offsetX,
14981501
offsetY,
1499-
shouldSetAriaExpanded
1502+
shouldSetAriaExpanded,
1503+
styles
15001504
} = this.props
1501-
1505+
const borderColor = (styles?.drilldown as { borderColor: string })
1506+
?.borderColor
15021507
return trigger ? (
15031508
<Popover
1509+
themeOverride={{
1510+
// use here own theme's color
1511+
borderColor: borderColor
1512+
}}
15041513
shouldSetAriaExpanded={shouldSetAriaExpanded}
15051514
isShowingContent={show}
15061515
defaultIsShowingContent={defaultShow}

packages/ui-drilldown/src/Drilldown/props.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,13 @@ type DrilldownOwnProps = {
136136
trigger?: React.ReactNode
137137

138138
/**
139-
* If a trigger is supplied, where should the `<Drilldown />` be placed (relative to the trigger)
139+
* If a trigger is supplied, where should the `<Drilldown />` be placed
140+
* (relative to the trigger)
141+
*
142+
* `stretch` will stretch the `Drilldown` to the same size as its `trigger`
143+
* (provided that the `trigger` is at least as large as the `Drilldown`).
144+
* In this case you should not set `width`/`maxHeight`, it will be set
145+
* automatically.
140146
*/
141147
placement?: PlacementPropValues
142148

packages/ui-drilldown/src/Drilldown/styles.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const generateStyle = (
5151
label: 'drilldown',
5252
overflow: 'visible', // needed for focus ring!
5353
borderColor: componentTheme.borderColor,
54-
5554
...(hasHighlightedOption && {
5655
'&:focus::before': {
5756
display: 'none'

packages/ui-popover/src/Popover/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ class Popover extends Component<PopoverProps, PopoverState> {
249249
}
250250
}
251251

252+
/**
253+
* Offsets the popover by the arrow size
254+
*/
252255
computeOffsets(placement: PopoverProps['placement']) {
253256
let { offsetX, offsetY } = this.props
254257

packages/ui-position/src/calculateElementPosition.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,18 @@ function offsetToPx(
616616

617617
function sortPlacement(placement: PlacementValuesWithoutOffscreenArray) {
618618
let [first, second] = placement
619-
620-
if (first === 'center' || first === 'stretch') {
619+
if (first === 'center') {
621620
;[first, second] = [second, first]
622621
}
623622
return [first, second] as PlacementValuesWithoutOffscreenArray
624623
}
625624

625+
/**
626+
* Returns the following:
627+
* - When the input is just 1 element, then `[input, 'center']`, else:
628+
* - if the first element is `center`, it reverses the order
629+
* - otherwise, it just returns the split input as an array
630+
*/
626631
function parsePlacement(placement: PlacementPropValues) {
627632
let parsed = placement.split(' ') as PlacementValuesWithoutOffscreenArray
628633

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,30 @@ const endPlacements: PlacementArray = [
3434
'end center',
3535
'end top',
3636
'end bottom',
37+
'end stretch',
3738
'center end',
3839
'end'
3940
]
4041
const startPlacements: PlacementArray = [
4142
'start center',
4243
'start top',
4344
'start bottom',
45+
'start stretch',
4446
'center start',
4547
'start'
4648
]
4749
const bottomPlacements: PlacementArray = [
4850
'bottom',
4951
'bottom end',
5052
'bottom start',
53+
'bottom stretch',
5154
'bottom center'
5255
]
5356
const topPlacements: PlacementArray = [
5457
'top',
5558
'top start',
5659
'top end',
60+
'top stretch',
5761
'top center'
5862
]
5963

@@ -85,7 +89,9 @@ const getArrowCorrections = (
8589
'top',
8690
'bottom',
8791
'top center',
88-
'bottom center'
92+
'bottom center',
93+
'top stretch',
94+
'bottom stretch'
8995
]
9096
const start: PlacementArray = ['top start', 'bottom start']
9197
const end: PlacementArray = ['top end', 'bottom end']

0 commit comments

Comments
 (0)