Skip to content

Commit d334cde

Browse files
authored
Remove gap shim (#5229)
* Remove flex gap shim
1 parent 8855023 commit d334cde

File tree

2 files changed

+2
-63
lines changed

2 files changed

+2
-63
lines changed

packages/@react-spectrum/layout/docs/Flex.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ The `Flex` component can be used to layout its children in one dimension with
3939
Any React Spectrum component can be used as a child, and `Flex` components can be nested to create
4040
more complex layouts.
4141

42-
In addition to the properties widely supported by CSS, React Spectrum also shims the `gap` property, along
43-
with `rowGap` and `columnGap`. These properties make it much easier to build layouts
44-
with consistent space between each item. The gap can be defined with [Spectrum dimension variables](styling.html#dimension-values)
42+
The `gap`, `rowGap` and `columnGap` can be defined with [Spectrum dimension variables](styling.html#dimension-values)
4543
to ensure consistency across applications, and allow the layout to adapt to different devices automatically.
46-
In addition, these values can be autocompleted in many IDEs for convenience.
44+
These values can be autocompleted in many IDEs for convenience.
4745

4846
All `Flex` props also support object syntax to define responsive layouts that change at certain breakpoints.
4947
See the [layout docs](layout.html#responsive-layout) for more details.

packages/@react-spectrum/layout/src/Flex.tsx

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {filterDOMProps} from '@react-aria/utils';
1616
import {FlexProps} from '@react-types/layout';
1717
import React, {forwardRef} from 'react';
1818
import styles from './flex-gap.css';
19-
import {useIsSSR} from '@react-aria/ssr';
2019

2120
const flexStyleProps: StyleHandlers = {
2221
direction: ['flexDirection', passthroughStyle],
@@ -36,32 +35,7 @@ function Flex(props: FlexProps, ref: DOMRef<HTMLDivElement>) {
3635
let {styleProps} = useStyleProps(otherProps);
3736
let {styleProps: flexStyle} = useStyleProps(otherProps, flexStyleProps);
3837
let domRef = useDOMRef(ref);
39-
let isSSR = useIsSSR();
4038

41-
// If a gap property is specified, and there is no native support or we're in SSR, use a shim.
42-
// Two divs are required for this: the outer one contains most style properties, and the inner
43-
// one is the flex container. Each item inside the flex container gets a margin around it based
44-
// on the gap, and the flex container has a negative margin to counteract this. The outer container
45-
// is necessary to allow nesting of flex containers with gaps, so that the inner CSS variable doesn't
46-
// override the outer one.
47-
if ((props.gap || props.rowGap || props.columnGap) && (isSSR || !isFlexGapSupported())) {
48-
let style = {
49-
...flexStyle.style,
50-
'--column-gap': props.columnGap != null ? responsiveDimensionValue(props.columnGap, matchedBreakpoints) : undefined,
51-
'--row-gap': props.rowGap != null ? responsiveDimensionValue(props.rowGap, matchedBreakpoints) : undefined,
52-
'--gap': props.gap != null ? responsiveDimensionValue(props.gap, matchedBreakpoints) : undefined
53-
};
54-
55-
return (
56-
<div {...filterDOMProps(otherProps)} {...styleProps} className={classNames(styles, 'flex-container', styleProps.className)} ref={domRef}>
57-
<div className={classNames(styles, 'flex', 'flex-gap')} style={style}>
58-
{children}
59-
</div>
60-
</div>
61-
);
62-
}
63-
64-
// If no gaps, or native support exists, then we only need to render a single div.
6539
let style = {
6640
...styleProps.style,
6741
...flexStyle.style
@@ -113,39 +87,6 @@ function flexWrapValue(value) {
11387
return value;
11488
}
11589

116-
117-
// Original licensing for the following method can be found in the
118-
// NOTICE file in the root directory of this source tree.
119-
// See https://github.com/Modernizr/Modernizr/blob/7efb9d0edd66815fb115fdce95fabaf019ce8db5/feature-detects/css/flexgap.js
120-
121-
let _isFlexGapSupported = null;
122-
function isFlexGapSupported() {
123-
if (_isFlexGapSupported != null) {
124-
return _isFlexGapSupported;
125-
}
126-
127-
if (typeof document === 'undefined') {
128-
return false;
129-
}
130-
131-
// create flex container with row-gap set
132-
var flex = document.createElement('div');
133-
flex.style.display = 'flex';
134-
flex.style.flexDirection = 'column';
135-
flex.style.rowGap = '1px';
136-
137-
// create two, elements inside it
138-
flex.appendChild(document.createElement('div'));
139-
flex.appendChild(document.createElement('div'));
140-
141-
// append to the DOM (needed to obtain scrollHeight)
142-
document.body.appendChild(flex);
143-
_isFlexGapSupported = flex.scrollHeight === 1; // flex container should be 1px high from the row-gap
144-
flex.parentNode.removeChild(flex);
145-
146-
return _isFlexGapSupported;
147-
}
148-
14990
/**
15091
* A layout container using flexbox. Provides Spectrum dimension values, and supports the gap
15192
* property to define consistent spacing between items.

0 commit comments

Comments
 (0)