Skip to content

Commit c8f0d1d

Browse files
authored
feat(Collapse): add horizontal animation (react-bootstrap#5993)
* fix: changed .modal-backdrop to .offcanvas-backdrop * Removed modalBsPrefix in Offcanvas * feat: Added Horizontal Collapse * Added width transition to Collapse API
1 parent 95f16d2 commit c8f0d1d

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

src/Collapse.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ const propTypes = {
117117
/**
118118
* The dimension used when collapsing, or a function that returns the
119119
* dimension
120-
*
121-
* _Note: Bootstrap only partially supports 'width'!
122-
* You will need to supply your own CSS animation for the `.width` CSS class._
123120
*/
124121
dimension: PropTypes.oneOfType([
125122
PropTypes.oneOf(['height', 'width']),
@@ -245,7 +242,7 @@ const Collapse = React.forwardRef<Transition<any>, CollapseProps>(
245242
className,
246243
children.props.className,
247244
collapseStyles[state],
248-
computedDimension === 'width' && 'width',
245+
computedDimension === 'width' && 'collapse-horizontal',
249246
),
250247
})
251248
}

test/CollapseSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ describe('<Collapse>', () => {
203203
assert.ok(node.className.indexOf('width') === -1);
204204
});
205205

206-
it('Should have width in class', () => {
206+
it('Should have collapse-horizontal in class', () => {
207207
function dimension() {
208208
return 'width';
209209
}
210210

211211
wrapper.setProps({ dimension });
212212
let node = wrapper.getDOMNode();
213-
assert.ok(node.className.indexOf('width') !== -1);
213+
assert.ok(node.className.indexOf('collapse-horizontal') !== -1);
214214
});
215215
});
216216

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function Example() {
2+
const [open, setOpen] = useState(false);
3+
4+
return (
5+
<>
6+
<Button
7+
onClick={() => setOpen(!open)}
8+
aria-controls="example-collapse-text"
9+
aria-expanded={open}
10+
>
11+
click
12+
</Button>
13+
<div style={{minHeight: '150px'}}>
14+
<Collapse in={open} dimension="width">
15+
<div id="example-collapse-text">
16+
<Card body style={{width: '400px'}}>
17+
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus
18+
terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer
19+
labore wes anderson cred nesciunt sapiente ea proident.
20+
</Card>
21+
</div>
22+
</Collapse>
23+
</div>
24+
</>
25+
);
26+
}
27+
28+
render(<Example />);

www/src/pages/utilities/transitions.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ComponentApi from '../../components/ComponentApi';
55
import ReactPlayground from '../../components/ReactPlayground';
66

77
import Collapse from '../../examples/Collapse';
8+
import CollapseHorizontal from '../../examples/CollapseHorizontal'
89
import Fade from '../../examples/Fade';
910

1011
# Transitions
@@ -19,6 +20,8 @@ as well as portable for using in other libraries. All React-bootstrap component
1920

2021
## Collapse
2122

23+
### Basic Example
24+
2225
Add a collapse toggle animation to an element or component.
2326

2427
<Callout title="Smooth animations">
@@ -32,6 +35,21 @@ Add a collapse toggle animation to an element or component.
3235

3336
<ReactPlayground codeText={Collapse} />
3437

38+
### Horizontal
39+
40+
Add a collapse toggle animation to an element or component to transition the width instead of height.
41+
42+
<Callout title="Smooth animations">
43+
If you're noticing choppy animations, and the component that's being
44+
collapsed has non-zero margin or padding, try wrapping the contents of
45+
your <code>{'<Collapse>'}</code> inside a node with no margin or
46+
padding, like the <code>{'<div>'}</code> in the example below. This will
47+
allow the height to be computed properly, so the animation can proceed
48+
smoothly.
49+
</Callout>
50+
51+
<ReactPlayground codeText={CollapseHorizontal} />
52+
3553
## Fade
3654

3755
Add a fade animation to a child element or component.

0 commit comments

Comments
 (0)