Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist
demo/dist
npm-debug.log
yarn.lock
.idea/
5 changes: 4 additions & 1 deletion src/Autowhatever.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@ export default class Autowhatever extends Component {
} = this.props;
const { isInputFocused } = this.state;
const renderedItems = multiSection ? this.renderSections() : this.renderItems();
const isOpen = (renderedItems !== null);
const isOpen = (
renderedItems !== null ||
renderItemsContainer !== defaultRenderItemsContainer
);
const ariaActivedescendant = this.getItemId(highlightedSectionIndex, highlightedItemIndex);
const containerProps = theme(
`react-autowhatever-${id}-container`,
Expand Down
21 changes: 21 additions & 0 deletions test/render-empty-items-with-items-container/Autowhatever.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import TestUtils from 'react-dom/test-utils';
import { expect } from 'chai';
import {
init,
getInputAttribute
} from '../helpers';
import AutowhateverApp, {
renderItemsContainer
} from './AutowhateverApp';

describe('Autowhatever with empty items and renderItemsContainer', () => {
beforeEach(() => {
renderItemsContainer.reset();
init(TestUtils.renderIntoDocument(<AutowhateverApp />));
});

it('should be open since this is rendered with a custom container', () => {
expect(getInputAttribute('aria-expanded')).to.equal('true');
});
});
50 changes: 50 additions & 0 deletions test/render-empty-items-with-items-container/AutowhateverApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { Component } from 'react';
import sinon from 'sinon';
import Autowhatever from '../../src/Autowhatever';
import items from './items';

export const renderItem = item => item.text;

export const renderItemsContainer = sinon.spy(({ containerProps, children }) => (
<div {...containerProps}>
{children}
<div className="my-items-container-footer">
Footer
</div>
</div>
));

export default class AutowhateverApp extends Component {
constructor() {
super();

this.state = {
value: ''
};
}

onChange = event => {
this.setState({
value: event.target.value
});
};

render() {
const { value } = this.state;
const inputProps = {
id: 'my-custom-input',
value,
onChange: this.onChange
};

return (
<Autowhatever
id="my-id"
renderItemsContainer={renderItemsContainer}
items={items}
renderItem={renderItem}
inputProps={inputProps}
/>
);
}
}
1 change: 1 addition & 0 deletions test/render-empty-items-with-items-container/items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default [];
18 changes: 18 additions & 0 deletions test/render-empty-items/Autowhatever.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import TestUtils from 'react-dom/test-utils';
import { expect } from 'chai';
import {
init,
getInputAttribute
} from '../helpers';
import AutowhateverApp from './AutowhateverApp';

describe('Autowhatever with empty items and default items container', () => {
beforeEach(() => {
init(TestUtils.renderIntoDocument(<AutowhateverApp />));
});

it('should be closed since this is rendered without a custom container', () => {
expect(getInputAttribute('aria-expanded')).to.equal('false');
});
});
39 changes: 39 additions & 0 deletions test/render-empty-items/AutowhateverApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React, { Component } from 'react';
import Autowhatever from '../../src/Autowhatever';
import items from './items';

export const renderItem = item => item.text;

export default class AutowhateverApp extends Component {
constructor() {
super();

this.state = {
value: ''
};
}

onChange = event => {
this.setState({
value: event.target.value
});
};

render() {
const { value } = this.state;
const inputProps = {
id: 'my-custom-input',
value,
onChange: this.onChange
};

return (
<Autowhatever
id="my-id"
items={items}
renderItem={renderItem}
inputProps={inputProps}
/>
);
}
}
1 change: 1 addition & 0 deletions test/render-empty-items/items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default [];