MCPcopy Create free account
hub / github.com/ElemeFE/element-react / setActiveItem

Method setActiveItem

src/carousel/Carousel.jsx:157–187  ·  view source on GitHub ↗
(index: number)

Source from the content-addressed store, hash-verified

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);

Callers 7

constructorMethod · 0.95
addItemMethod · 0.95
removeItemMethod · 0.95
prevMethod · 0.95
nextMethod · 0.95
handleItemClickMethod · 0.80
componentDidMountMethod · 0.80

Calls 1

filterMethod · 0.45

Tested by

no test coverage detected