Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): controlled behavior #1676

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

nuke-ellington
Copy link
Collaborator

@nuke-ellington nuke-ellington commented Jan 31, 2025

💡 What is the current behavior?

Checklist of components with internal state:

  • ix-drawer
  • ix-flip-tile
  • ix-group
  • ix-menu
  • ix-menu-about
  • ix-menu-settings
  • ix-pagination
  • ix-pane
  • ix-select
  • ix-slider
  • ix-toggle
  • ix-tree (TBD -> separate PR)

GitHub Issue Number: IX-1920

🆕 What is the new behavior?

🏁 Checklist

A pull request can only be merged if all of these conditions are met (where applicable):

  • 🦮 Accessibility (a11y) features were implemented
  • 🗺️ Internationalization (i18n) - no hard coded strings
  • 📲 Responsiveness - components handle viewport changes and content overflow gracefully
  • 📄 Documentation was reviewed/updated (pnpm run docs)
  • 🧪 Unit tests were added/updated and pass (pnpm test)
  • 📸 Visual regression tests were added/updated and pass (Guide)
  • 🧐 Static code analysis passes (pnpm lint)
  • 🏗️ Successful compilation (pnpm build, changes pushed)

👨‍💻 Help & support

@nuke-ellington nuke-ellington marked this pull request as draft January 31, 2025 13:13
Copy link

changeset-bot bot commented Feb 11, 2025

🦋 Changeset detected

Latest commit: 1792cad

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@siemens/ix-angular Minor
@siemens/ix Minor
@siemens/ix-vue Minor
@siemens/ix-aggrid Patch
@siemens/ix-react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@nuke-ellington nuke-ellington marked this pull request as ready for review February 12, 2025 09:00
@nuke-ellington nuke-ellington changed the title feat(core/drawer): add prevent default logic feat(core): controlled behavior Feb 12, 2025
'@siemens/ix-vue': minor
---

Expsose index of **ix-flip-tile** and add toggle event.
Copy link
Collaborator

@jul-lam jul-lam Feb 13, 2025

Choose a reason for hiding this comment

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

Do we already have a changeset for the prevent default?

if (this.isFlipAnimationActive) {
return;
}

this.isFlipAnimationActive = true;

setTimeout(() => {
Copy link
Collaborator

@jul-lam jul-lam Feb 13, 2025

Choose a reason for hiding this comment

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

Should we clear the timeout if the animation is still active when disconnecting? Probably not necessary.

packages/core/src/components/menu/menu.tsx Show resolved Hide resolved
Comment on lines 53 to 71
test('should not open about', async ({ mount, page }) => {
await mount(`
<ix-menu>
<ix-menu-about>
</ix-menu-about>
</ix-menu>
`);
const element = page.locator('ix-menu');

await element.evaluate((e) => {
e.addEventListener('openAbout', (event) => event.preventDefault());
});

const aboutButton = element.locator('ix-menu-item#aboutAndLegal');
await aboutButton.click();

let about = page.locator('ix-menu-about');
await expect(about).not.toBeVisible();
});
Copy link
Collaborator

@jul-lam jul-lam Feb 13, 2025

Choose a reason for hiding this comment

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

Maybe add the settings test (should not open settings) to the menu.ct.ts

Comment on lines +114 to +118
const { defaultPrevented } = this.pageSelected.emit(this.selectedPage);

if (defaultPrevented) {
this.selectedPage = oldIndex;
}
Copy link
Collaborator

@jul-lam jul-lam Feb 13, 2025

Choose a reason for hiding this comment

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

Could we pull this part up so we don't have to reset the value later on?

Comment on lines +163 to +168
const { defaultPrevented } = this.emitInputEvent();

if (defaultPrevented) {
this.rangeInput = oldValue;
this.slider.value = oldValue.toString();
}
Copy link
Collaborator

@jul-lam jul-lam Feb 13, 2025

Choose a reason for hiding this comment

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

Could we pull this part up so we don't have to reset the value later on?

Comment on lines +113 to +118
const { defaultPrevented } = this.checkedChange.emit(this.checked);

if (defaultPrevented) {
this.indeterminate = wasIndeterminate;
this.checked = oldChecked;
}
Copy link
Collaborator

@jul-lam jul-lam Feb 13, 2025

Choose a reason for hiding this comment

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

Could we pull this part up so we don't have to reset the value later on?

Comment on lines +63 to +82
test('toggle - prevent default', async ({ mount, page }) => {
await mount(`
<ix-flip-tile>
<ix-flip-tile-content>Page 1</ix-flip-tile-content>
<ix-flip-tile-content>Page 2</ix-flip-tile-content>
</ix-flip-tile`);
const flipTile = page.locator('ix-flip-tile');
await expect(flipTile).toHaveClass(/hydrated/);
await flipTile.evaluate((d: HTMLIxFlipTileElement) =>
d.addEventListener('toggle', (event) => {
event.preventDefault();
})
);
await flipTile.locator('ix-icon-button').click();
await flipTile.evaluate((d: HTMLIxFlipTileElement) => (d.index = 1));
const pageOne = flipTile.locator('ix-flip-tile-content').nth(0);
const pageTwo = flipTile.locator('ix-flip-tile-content').nth(1);
await expect(pageOne).toBeVisible();
await expect(pageTwo).not.toBeVisible();
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

You test index prop in line 77. We could also add a additional test to test if the index really change the flip content

Copy link

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.

3 participants