(index: number)
| 155 | } |
| 156 | |
| 157 | setActiveItem(index: number): void { |
| 158 | let { activeIndex } = this.state; |
| 159 | |
| 160 | if (typeof index === 'string') { |
| 161 | const filteredItems = this.state.items.filter(item => item.props.name === index); |
| 162 | |
| 163 | if (filteredItems.length > 0) { |
| 164 | index = this.state.items.indexOf(filteredItems[0]); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | index = Number(index); |
| 169 | |
| 170 | if (isNaN(index) || index !== Math.floor(index)) { |
| 171 | process.env.NODE_ENV !== 'production' && |
| 172 | console.warn('[Element Warn][Carousel]index must be an integer.'); |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | let length = this.state.items.length; |
| 177 | |
| 178 | if (index < 0) { |
| 179 | activeIndex = length - 1; |
| 180 | } else if (index >= length) { |
| 181 | activeIndex = 0; |
| 182 | } else { |
| 183 | activeIndex = index; |
| 184 | } |
| 185 | |
| 186 | this.setState({ activeIndex }); |
| 187 | } |
| 188 | |
| 189 | prev(): void { |
| 190 | this.setActiveItem(this.state.activeIndex - 1); |
no test coverage detected