mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 15:07:13 +08:00
fix(accordion): state updates if value changes (#27463)
Issue number: resolves #27461 --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> If an accordion group has a value, and an accordion updates its value to equal the accordion group value then the state of the accordion does not change. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - If an accordion value changes it will call `this.updateState` to see if it should open in the event its value now matches the value of the parent accordion group. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> Dev build: `7.0.7-dev.11683898881.13edb102`
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
import type { ComponentInterface } from '@stencil/core';
|
import type { ComponentInterface } from '@stencil/core';
|
||||||
import { Component, Element, Host, Prop, State, h } from '@stencil/core';
|
import { Component, Element, Host, Prop, State, Watch, h } from '@stencil/core';
|
||||||
import { chevronDown } from 'ionicons/icons';
|
import { chevronDown } from 'ionicons/icons';
|
||||||
|
|
||||||
import { config } from '../../global/config';
|
import { config } from '../../global/config';
|
||||||
@ -56,6 +56,10 @@ export class Accordion implements ComponentInterface {
|
|||||||
* value.
|
* value.
|
||||||
*/
|
*/
|
||||||
@Prop() value = `ion-accordion-${accordionIds++}`;
|
@Prop() value = `ion-accordion-${accordionIds++}`;
|
||||||
|
@Watch('value')
|
||||||
|
valueChanged() {
|
||||||
|
this.updateState();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If `true`, the accordion cannot be interacted with.
|
* If `true`, the accordion cannot be interacted with.
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { AccordionGroup } from '../../accordion-group/accordion-group.tsx';
|
|||||||
import { Item } from '../../item/item.tsx';
|
import { Item } from '../../item/item.tsx';
|
||||||
import { Accordion } from '../accordion.tsx';
|
import { Accordion } from '../accordion.tsx';
|
||||||
|
|
||||||
it('should open correct accordions', async () => {
|
it('should open correct accordions when accordion group value is set', async () => {
|
||||||
const page = await newSpecPage({
|
const page = await newSpecPage({
|
||||||
components: [Item, Accordion, AccordionGroup],
|
components: [Item, Accordion, AccordionGroup],
|
||||||
html: `
|
html: `
|
||||||
@ -40,6 +40,42 @@ it('should open correct accordions', async () => {
|
|||||||
expect(accordions[2].classList.contains('accordion-collapsed')).toEqual(true);
|
expect(accordions[2].classList.contains('accordion-collapsed')).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should open correct accordions when accordion value is set', async () => {
|
||||||
|
const page = await newSpecPage({
|
||||||
|
components: [Item, Accordion, AccordionGroup],
|
||||||
|
html: `
|
||||||
|
<ion-accordion-group animated="false" value="first">
|
||||||
|
<ion-accordion>
|
||||||
|
<ion-item slot="header">Label</ion-item>
|
||||||
|
<div slot="content">Content</div>
|
||||||
|
</ion-accordion>
|
||||||
|
<ion-accordion value="second">
|
||||||
|
<ion-item slot="header">Label</ion-item>
|
||||||
|
<div slot="content">Content</div>
|
||||||
|
</ion-accordion>
|
||||||
|
<ion-accordion value="third">
|
||||||
|
<ion-item slot="header">Label</ion-item>
|
||||||
|
<div slot="content">Content</div>
|
||||||
|
</ion-accordion>
|
||||||
|
</ion-accordion-group>
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
|
||||||
|
const accordionGroup = page.body.querySelector('ion-accordion-group');
|
||||||
|
const accordions = accordionGroup.querySelectorAll('ion-accordion');
|
||||||
|
|
||||||
|
accordions.forEach((accordion) => {
|
||||||
|
expect(accordion.classList.contains('accordion-collapsed')).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
accordions[0].value = 'first';
|
||||||
|
await page.waitForChanges();
|
||||||
|
|
||||||
|
expect(accordions[0].classList.contains('accordion-collapsed')).toEqual(false);
|
||||||
|
expect(accordions[1].classList.contains('accordion-collapsed')).toEqual(true);
|
||||||
|
expect(accordions[2].classList.contains('accordion-collapsed')).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
it('should open more than one accordion when multiple="true"', async () => {
|
it('should open more than one accordion when multiple="true"', async () => {
|
||||||
const page = await newSpecPage({
|
const page = await newSpecPage({
|
||||||
components: [Item, Accordion, AccordionGroup],
|
components: [Item, Accordion, AccordionGroup],
|
||||||
|
|||||||
Reference in New Issue
Block a user