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

refactor: Update relevant components to handle slotting after init #3889

Merged
merged 25 commits into from
Jan 22, 2022

Conversation

driskull
Copy link
Member

@driskull driskull commented Jan 10, 2022

Related Issue: #3686

Summary

refactor: Update relevant components to use ConditionalSlotComponent

Also spawned: #3881

@driskull driskull self-assigned this Jan 10, 2022
@github-actions github-actions bot added this to the Sprint 01/03 - 01/14 milestone Jan 10, 2022
@github-actions github-actions bot added the refactor Issues tied to code that needs to be significantly reworked. label Jan 10, 2022
Copy link
Member Author

@driskull driskull left a comment

Choose a reason for hiding this comment

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

@jcfranco I think this needs your mutation observer fixes for conditionalSlot. Some getSlotted are not working correctly. I'll wait for that to get in.

src/utils/dom.ts Outdated
@@ -159,10 +159,11 @@ export async function focusElement(el: CalciteFocusableElement): Promise<void> {
interface GetSlottedOptions {
all?: boolean;
direct?: boolean;
matches?: string;
Copy link
Member Author

Choose a reason for hiding this comment

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

@jcfranco what do you think? Should we have a way to do getSlotted(this.el, { matches: "calcite-link"});

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 selector should work here. Let me know if it doesn't match your needs (badumtss🥁) .

Copy link
Member Author

Choose a reason for hiding this comment

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

@jcfranco selector queries the element for children, matches tests the element.

Copy link
Member Author

Choose a reason for hiding this comment

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

the matches is more of a filter.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha. Looks like you found a hole in this util. 🍩 I think queries using selector should include the slotted element. WDYT? Fortunately, there are only 2 selector usages so far:

  1. https://github.com/Esri/calcite-components/blob/2ec984876f33939d06c7ad0b47c9040f1a7d0a9d/src/components/calcite-tree-item/calcite-tree-item.tsx#L414
  2. https://github.com/Esri/calcite-components/blob/5e0f9f259d160f7826dbf1be56b05ad52b0d0add/src/components/calcite-alert/calcite-alert.tsx#L241

I'll create an issue for the above and can tackle this separately.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah we can either update how selector works or matches.

src/utils/dom.ts Outdated
selector?: string;
}

const defaultSlotSelector = "> :not([slot])";
const defaultSlotSelector = ":not([slot])";
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why I had the > but this might be something we need??

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, so can't do direct selector because of the scope. Instead, have to filter child nodes first.

I tried using :scope > but that wasn't working either.
https://developer.mozilla.org/en-US/docs/Web/CSS/:scope

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. Do the current spec tests cover this? Wonder why it didn't pick this up.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do the current spec tests cover this? Wonder why it didn't pick this up.

We weren't using a selector like this for all default slot queries.

: (Array.from(
el.querySelectorAll("calcite-action:not([slot=trigger])")
) as HTMLCalciteActionElement[]);
const actionElements = getSlotted(el, { all: true, matches: "calcite-action" }) as any;
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to test this cleanup...

Copy link
Member

Choose a reason for hiding this comment

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

Need to test this cleanup...

Test successful?

Also, can you type provide the type in the helper?

const actionElements = getSlotted<HTMLCalciteAction>(/* ... */);

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this issue needs to happen first.... #3881

Copy link
Member Author

Choose a reason for hiding this comment

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

Test successful?

Yes this seems to be working.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, can you type provide the type in the helper?

The typings need some updates so that it correctly reports an array of items. Currently, it thinks its a single element.

@jcfranco
Copy link
Member

#3871 just landed, so you the util should work more reliably and you now have access to the test helper (for named slots) if needed.

@driskull driskull requested a review from jcfranco January 18, 2022 19:29
@driskull driskull marked this pull request as ready for review January 19, 2022 01:18
@driskull driskull requested a review from a team as a code owner January 19, 2022 01:18
: (Array.from(
el.querySelectorAll("calcite-action:not([slot=trigger])")
) as HTMLCalciteActionElement[]);
const actionElements = getSlotted(el, { all: true, matches: "calcite-action" }) as any;
Copy link
Member

Choose a reason for hiding this comment

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

Need to test this cleanup...

Test successful?

Also, can you type provide the type in the helper?

const actionElements = getSlotted<HTMLCalciteAction>(/* ... */);

src/components/calcite-combobox/calcite-combobox.e2e.ts Outdated Show resolved Hide resolved
src/components/calcite-input/calcite-input.tsx Outdated Show resolved Hide resolved
src/components/calcite-card/calcite-card.tsx Outdated Show resolved Hide resolved
src/utils/dom.ts Outdated
@@ -159,10 +159,11 @@ export async function focusElement(el: CalciteFocusableElement): Promise<void> {
interface GetSlottedOptions {
all?: boolean;
direct?: boolean;
matches?: string;
Copy link
Member

Choose a reason for hiding this comment

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

Gotcha. Looks like you found a hole in this util. 🍩 I think queries using selector should include the slotted element. WDYT? Fortunately, there are only 2 selector usages so far:

  1. https://github.com/Esri/calcite-components/blob/2ec984876f33939d06c7ad0b47c9040f1a7d0a9d/src/components/calcite-tree-item/calcite-tree-item.tsx#L414
  2. https://github.com/Esri/calcite-components/blob/5e0f9f259d160f7826dbf1be56b05ad52b0d0add/src/components/calcite-alert/calcite-alert.tsx#L241

I'll create an issue for the above and can tackle this separately.

src/utils/dom.ts Outdated
selector?: string;
}

const defaultSlotSelector = "> :not([slot])";
const defaultSlotSelector = ":not([slot])";
Copy link
Member

Choose a reason for hiding this comment

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

Interesting. Do the current spec tests cover this? Wonder why it didn't pick this up.

@driskull driskull changed the title refactor: Update relevant components to use ConditionalSlotComponent refactor: Update relevant components to handle slotting after init Jan 19, 2022
@driskull driskull requested a review from jcfranco January 21, 2022 18:08
@eriklharper
Copy link
Contributor

/merge master

# Conflicts:
#	src/components/calcite-input/calcite-input.tsx
@driskull
Copy link
Member Author

@jcfranco anything else I need to do to get this one merged?

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.

Just had one suggestion, but this LGTM! 🎉

Anything else that came up will be tackled separately.

@@ -81,6 +90,11 @@ export class CalciteRadioButtonGroup {

connectedCallback(): void {
this.passPropsToRadioButtons();
this.mutationObserver?.observe(this.el, { childList: true, subtree: true });
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to watch for changes to radio-button children? I don't think it supports this, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jcfranco I don't think so. The props should only go down the dom right?

Copy link
Member

Choose a reason for hiding this comment

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

The props should only go down the dom right?

If I understand correctly, only one level, yes.

@driskull driskull merged commit b00bdf7 into master Jan 22, 2022
@driskull driskull deleted the dris0000/conditional-slot-round-2 branch January 22, 2022 00:09
y0n4 pushed a commit that referenced this pull request Jan 24, 2022
…3889)

* refactor: Update relevant components to use ConditionalSlotComponent #3686

* cleanup

* cleanup

* cleanup

* fix links that aren't direct slots

* remove assigned slot check, only get direct children

* fix test

* cleanup

* cleanup

* partial review fixes

* revert changes to combobox and card
y0n4 pushed a commit that referenced this pull request Jan 27, 2022
* fix(label, input, input-message)!: deprecate and no longer support status prop for calcite-label

* alter tests for status being passed in calcite label

* update the readme for labels using status and add status prop to input/input-message

* add deprecated comment for status prop

* refactor(panel, shell, tree-item): Add keys to conditionally rendered slots. (#3962)

* refactor(panel, shell, tree-item): Add keys to conditionally rendered slots.

* add const for key.

* fix code

* review cleanup

* feat(panel): Add method to scroll content. #3924 (#3960)

* ci(screener): updating to Chrome 97 (#3940)

* 1.0.0-next.373

* docs: update component READMEs (#3972)

Co-authored-by: jcfranco <jcfranco@users.noreply.github.com>

* ci(screener): enlarging screen resolution (#3977)

* refactor(input): fix all types that are any (#3981)

* refactor: Update relevant components to handle slotting after init (#3889)

* refactor: Update relevant components to use ConditionalSlotComponent #3686

* cleanup

* cleanup

* cleanup

* fix links that aren't direct slots

* remove assigned slot check, only get direct children

* fix test

* cleanup

* cleanup

* partial review fixes

* revert changes to combobox and card

* refactor(slider): remove drag event listeners on component disconnected (#3969)

* refactor(slider): remove eventListeners on DOM disconnected

* feedback changes

* add private method for duplicate code

* rename method

* build: update browserslist db (#3985)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* test(input): when both 'ArrowUp' and 'ArrowDown' are pressed at the same time most recently pressed key takes over (#3989)

Co-authored-by: Eliza Khachatryan <eli97736@esri.com>

* alter verbiage of deprecated prop

* ci(screener): restoring pre-Sauce integration settings (#3994)

* docs(template): provide context for the repro samples (#3970)

* docs(templates): provide content for the repro samples

* use cc latest version

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* chore: pin node 16 and npm 8 for volta (#3964)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* docs(readme): remove sketch info until it is up to date (#3996)

* fix(date-picker): update utils locale to get the lang code if regional code is not found (#3968)

* fix(date-picker): update utils locale to get the lang code if regional code is not found

* alter util changes based from pr comments

* 1.0.0-next.374

* ci: allow primary and secondary contacts to merge on all prs (#3999)

* ci: allow primary and secondary contacts to merge on all prs

* cleanup

* use admin token

* fix(date-picker, input-date-picker): update pt-BR and pt-PT localization files (#3980)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* feat(tree):  multi-selection no longer requires holding shift key (#3733)

* fix(tree): enable multi select with pointer

* save selected items at main level

* fix single selection mode

* deselect siblings when mode is single

* fix deselecting tree item when mode is multi

* fix deselecting with shift keydown

* refactor e2e test

* remove unused imports in e2e

* feedback changes

* emit calciteTreeSelect event without shift key

* refactor code

* add e2e test and feedback changes

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* 1.0.0-next.375

* test(dropdown): correct logical errors in the test (#3998)

* test(dropdown): correct logical errors in the test

* assert both events after each toggle action and  use page.waitForEvent before doing assertions

Co-authored-by: Eliza Khachatryan <eli97736@esri.com>

* deprecate and restore the use of status prop

* restore reading status prop from label

Co-authored-by: Matt Driscoll <mdriscoll@esri.com>
Co-authored-by: Erik Harper <eharperdicianno@esri.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ben Elan <benelan@users.noreply.github.com>
Co-authored-by: jcfranco <jcfranco@users.noreply.github.com>
Co-authored-by: Anveshreddy mekala <anv11827@esri.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Eliza Khachatryan <elijbet@gmail.com>
Co-authored-by: Eliza Khachatryan <eli97736@esri.com>
Co-authored-by: JC Franco <jfranco@esri.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Issues tied to code that needs to be significantly reworked.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants