Skip to content

add Collapse component #79#201

Merged
eddywashere merged 24 commits intoreactstrap:masterfrom
LiJinyao:collapse
Nov 1, 2016
Merged

add Collapse component #79#201
eddywashere merged 24 commits intoreactstrap:masterfrom
LiJinyao:collapse

Conversation

@LiJinyao
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/Collapse.js Outdated
this.element.style.height = `${this.getHeight()}px`;
});
this.transitionTag = setTimeout(() => {
this.setState({ collapse: SHOWN });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the bootstrap js removes the height inline style after it has been shown. This would likely prevent any issues when added content and then collapsing the content again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review! The height inline style will be removed after setState called. Because there is no style declaration in the render function, so the inline height will be removed after rerender.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh Sorry! I found the problem. I'll fix it.

import Collapse from '../Collapse';

describe('Collapse', () => {
it('should render children', () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage went down. Could you setup jasmine.clock here since you're using setTimeout.

  beforeEach(() => {
    jasmine.clock().install();
  });

  afterEach(() => {
    jasmine.clock().uninstall();
  });

After prop changes, I believe you'll need to then use, jasmine.clock().tick(400); to move the virtual clock forward and test for the changes.

Comment thread webpack.dev.config.js Outdated
'/components/tabs/',
'/components/jumbotron/',
'/components/alerts/',
'/components/collapse',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a trailing / to generate the correct route path. I noticed a console warning regarding the active class applied to the nav .

Comment thread src/__tests__/Collapse.spec.js Outdated
expect(wrapper.instance().props.isOpen).toEqual(false);
});

it('should render with calss "collapse"', () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of typos here, calss -> class

Comment thread src/Collapse.js Outdated
// will open
this.setState({ collapse: SHOW }, () => {
// start transition
this.element.style.height = `${this.getHeight()}px`;
Copy link
Copy Markdown
Member

@eddywashere eddywashere Oct 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on moving these dom attribute changes over to react via setState? Would it still work or would the timing be off? I know some components break outside the react way of doing things but I'd like to only do that when absolutely necessary. This change doesn't have to happen in this PR either.

// apply via setState
setState({height: `${this.getHeight()}px`})

// in render
<div
        {...attributes}
        style={...attributes.style, height: this.state.height}
        className={classes}
        ref={(c) => { this.element = c; }}
      />

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the timing will be off at first, now I am trying to move these dom attribute changes to react. Let's see if it will work fine.

Comment thread src/Collapse.js Outdated
collapseClass
);
return (
<div
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update this to use the Tag (tag) prop pattern that other components use?

Comment thread src/Collapse.js Outdated
super(props);
this.state = {
collapse: props.isOpen ? SHOWN : HIDDEN,
height: 0,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should height be set to null isOpen is true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops, Yes it is. Thanks for your patient review!

@eddywashere eddywashere merged commit ddbf0dd into reactstrap:master Nov 1, 2016
eddywashere pushed a commit that referenced this pull request Nov 2, 2016
#216)

* add NavbarToggler example

* feat(Collapse): add Collapse component #79 (#201)

* init collapse

* add collapse animation

* add margin between toggle button and collapse

* disable lint on force refresh DOM line.

* add test to Collapse

* remove height after shown

* Revert "remove height after shown"

This reverts commit eff9353.

* remove height after shown.

* add more test

* use setState() to set inline height style

* remove custom tag in doc

* add inline style test

* remove comment

* set height to null when isOpen is true

* add initial state test

* chore(release): adding 3.8.0 (#217)

* chore(release): adding 3.8.0

* feat(Collapse): add cssModule support

* feat(refs): add getRef to focusable components (#218)

* chore(release): adding 3.8.1 (#219)

* add NavbarToggler example

* update example to use Collapse component
@LiJinyao LiJinyao deleted the collapse branch December 10, 2016 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants