-
Notifications
You must be signed in to change notification settings - Fork 77
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
Conversation
There was a problem hiding this 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; |
There was a problem hiding this comment.
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"});
There was a problem hiding this comment.
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🥁) .
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- https://github.com/Esri/calcite-components/blob/2ec984876f33939d06c7ad0b47c9040f1a7d0a9d/src/components/calcite-tree-item/calcite-tree-item.tsx#L414
- 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.
There was a problem hiding this comment.
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])"; |
There was a problem hiding this comment.
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??
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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>(/* ... */);
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/components/calcite-radio-button-group/calcite-radio-button-group.tsx
Show resolved
Hide resolved
#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. |
# Conflicts: # src/components/calcite-inline-editable/calcite-inline-editable.tsx
: (Array.from( | ||
el.querySelectorAll("calcite-action:not([slot=trigger])") | ||
) as HTMLCalciteActionElement[]); | ||
const actionElements = getSlotted(el, { all: true, matches: "calcite-action" }) as any; |
There was a problem hiding this comment.
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-inline-editable/calcite-inline-editable.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; |
There was a problem hiding this comment.
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:
- https://github.com/Esri/calcite-components/blob/2ec984876f33939d06c7ad0b47c9040f1a7d0a9d/src/components/calcite-tree-item/calcite-tree-item.tsx#L414
- 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])"; |
There was a problem hiding this comment.
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.
/merge master |
# Conflicts: # src/components/calcite-input/calcite-input.tsx
@jcfranco anything else I need to do to get this one merged? |
There was a problem hiding this 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 }); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
* 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>
Related Issue: #3686
Summary
refactor: Update relevant components to use ConditionalSlotComponent
Also spawned: #3881