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

fix(tabs): redisplay close button when more than one tab is closable #11492

Merged
merged 15 commits into from
Mar 4, 2025

Conversation

josercarcamo
Copy link
Contributor

Related Issue: #10183

Summary

Redisplays x when > 1 closable tab is added programmatically.

@github-actions github-actions bot added the bug Bug reports for broken functionality. Issues should include a reproduction of the bug. label Feb 7, 2025
@josercarcamo josercarcamo added the pr ready for visual snapshots Adding this label will run visual snapshot testing. label Feb 7, 2025
@josercarcamo josercarcamo added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels Feb 7, 2025
Copy link
Member

@jcfranco jcfranco left a comment

Choose a reason for hiding this comment

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

This is looking good, @josercarcamo! One more pass, and I think we can land this.

We'll still need to handle the case where closed tab-titles are restored via the close prop being updated (i.e., items are closed via prop only). This can be done in a follow-up PR.

*
* @private
*/
firstTabClosable = false;
Copy link
Member

Choose a reason for hiding this comment

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

Would renaming this private prop to something like lastClosableTabWasClosed help avoid the comment? Making the prop private could also remove the JSDoc tag if we need the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should devise another name because lastClosableTabWasClosed is kind of long and not specific. Also, I only added to tag because other properties have tags. I can remove it and just make the property private.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, as long as it's specific and helps remove the comment. IMO, maintainability outweighs length due to the variable's scope, but I hear ya.

*
* @private
*/
firstTabClosable = false;
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be moved to the private props region.

@@ -374,6 +381,10 @@ export class TabNav extends LitElement {
slottedElements.forEach((child) => {
this.intersectionObserver?.observe(child);
});
if (slottedElements.length > 1 && this.firstTabClosable) {
(slottedElements[0] as TabTitle["el"]).closable = true;
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs to check for closable=false to determine which tab-title should be updated instead of assuming it's the first one (e.g., if the first 4 out of 5 are closed, then a new tab and tab-title are added). Also, should firstTabClosable be reset here?

@josercarcamo josercarcamo added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels Feb 12, 2025
@josercarcamo josercarcamo added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels Feb 12, 2025
@josercarcamo
Copy link
Contributor Author

@jcfranco one more review please.

@jcfranco jcfranco changed the title fix(tabs): x redisplays when > 1 closable tab fix(tabs): redisplay close button when more than one tab is closable Feb 21, 2025
Copy link
Member

@jcfranco jcfranco left a comment

Choose a reason for hiding this comment

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

Had some additional comments, but this LGTM!

✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️
✖️📑✖️✖️✖️📑✖️✖️📑📑✖️✖️📑📑📑✖️✖️📑📑📑✖️📑📑📑📑✖️📑✖️
✖️📑📑✖️✖️📑✖️📑✖️✖️📑✖️✖️📑✖️✖️📑✖️✖️✖️✖️📑✖️✖️✖️✖️📑✖️
✖️📑✖️📑✖️📑✖️📑✖️✖️📑✖️✖️📑✖️✖️📑✖️✖️✖️✖️📑📑📑✖️✖️📑✖️
✖️📑✖️✖️📑📑✖️📑✖️✖️📑✖️✖️📑✖️✖️📑✖️✖️✖️✖️📑✖️✖️✖️✖️✖️✖️
✖️📑✖️✖️✖️📑✖️✖️📑📑✖️✖️📑📑📑✖️✖️📑📑📑✖️📑📑📑📑✖️📑✖️
✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️✖️

@@ -370,10 +372,20 @@ export class TabNav extends LitElement {
private onSlotChange(event: Event): void {
this.intersectionObserver?.disconnect();

const slottedElements = slotChangeGetAssignedElements(event, "calcite-tab-title");
const slottedElements = slotChangeGetAssignedElements<TabTitle["el"]>(
Copy link
Member

Choose a reason for hiding this comment

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

I think you could replace slottedElements with tabTitles directly to simplify.

slottedElements.forEach((child) => {
this.intersectionObserver?.observe(child);
});
const visibleTabTitlesIndices = this.visibleTabTitlesIndices;
Copy link
Member

Choose a reason for hiding this comment

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

You could reuse slottedElements/tabTitles and eliminate one extra DOM query by adding a function that returns the visible tab-title indices from an array of tab-titles.

@@ -405,5 +405,24 @@ describe("calcite-tabs", () => {

expect(selectedTitleOnEmit).toBe("Tab 2 Title");
});

it("should hide x when last closable tab and display x when > 1 closable tabs", async () => {
Copy link
Member

Choose a reason for hiding this comment

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

For extra coverage, could you update or add a test for closing tabs 1–3? If adding a new test, could you group them in a describe block?

@jcfranco
Copy link
Member

@josercarcamo FYI, I updated the PR title to better align with our PR naming conventions.

Copy link
Contributor

github-actions bot commented Mar 3, 2025

This PR has been automatically marked as stale because it has not had recent activity. Please close your PR if it is no longer relevant. Thank you for your contributions.

@github-actions github-actions bot added the Stale Issues or pull requests that have not had recent activity. label Mar 3, 2025
…calcite-design-system into josercarcamo/10183-redisplay-tab-x
@josercarcamo josercarcamo added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels Mar 3, 2025
@josercarcamo josercarcamo merged commit 3150fe5 into dev Mar 4, 2025
14 checks passed
@josercarcamo josercarcamo deleted the josercarcamo/10183-redisplay-tab-x branch March 4, 2025 00:10
benelan added a commit that referenced this pull request Mar 6, 2025
* origin/dev: (80 commits)
  build(deps): update nx monorepo to v20.4.6 (#11662)
  build(deps): update arcgis to ^4.32.7 (#11648)
  build: update browserslist db (#11639)
  build(deps): update eslint (#11670)
  build(deps): update dependency chromatic to v11.26.1 (#11669)
  build(deps): update dependency rollup to v4.34.9 (#11661)
  build(deps): update dependency tsx to v4.19.3 (#11658)
  chore: release next
  docs(text-area): update limitText description (#11672)
  feat(block, block-section): add `expanded` property and deprecate `open` property (#11582)
  feat(list-item, list): add `expanded` property and deprecate `open` property (#11003)
  chore: release next
  fix(tabs): redisplay close button when more than one tab is closable (#11492)
  test(shell-panel): Fix token story set up (#11635)
  chore: set up 3rd-party license generation (#11640)
  build(deps): update dependency happy-dom to v17.1.8 (#11649)
  build(deps): update dependency prettier to v3.5.2 (#11642)
  build(deps): update dependency happy-dom to v17.1.6 (#11641)
  chore: release next
  fix(card-group): Restore default gap spacing (#11638)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports for broken functionality. Issues should include a reproduction of the bug. pr ready for visual snapshots Adding this label will run visual snapshot testing. Stale Issues or pull requests that have not had recent activity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants