-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
chore(web-components): use predicate function instead of instanceof in Accordion #32822
chore(web-components): use predicate function instead of instanceof in Accordion #32822
Conversation
📊 Bundle size report✅ No changes found |
🕵 fluentui-web-components-v3 No visual regressions between this PR and main |
7c2686d
to
23d7954
Compare
/azp run |
Azure Pipelines successfully started running 4 pipeline(s). |
* | ||
* @public | ||
*/ | ||
export function isAccordion(element: Element): element is Accordion { |
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.
Should element
be HTMLElement
instead?
export { styles as accordionStyles } from './accordion.styles.js'; | ||
export { definition as accordionDefinition } from './accordion.definition.js'; | ||
export { template as accordionTemplate } from './accordion.template.js'; |
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.
Capitalize AccordionStyles
and AccordionTemplate
- Also in PR #32075
(item: Element | BaseAccordionItem) => item instanceof BaseAccordionItem && item.expanded, | ||
) ?? this.accordionItems[0] | ||
); | ||
private findExpandedItem(): BaseAccordionItem | null { |
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 based on the changes this can't return null
anymore, only undefined
?
This pull request has been automatically marked as stale because it was marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 5 days of this comment. Thank you for your contributions to Fluent UI! |
Previous Behavior
In systems which bundle components individually, we noticed that by using
instanceof
in theAccordion
class, we're pulling theBaseAccordion
class into our bundles.New Behavior
This PR introduces type predicate functions,
isAccordionItem
andisAccordion
, to cheaply determine if a child component is one which is expected. These functions do this by checking if thetagName
ends with abaseName
value, soisAccordionItem(element)
will return true ifelement.tagName
ends with "accordion-item".Some other changes:
index.ts
exportsaccordionDefinition
andaccordionItemDefinition
. These should be deprecated and removed in favor of the more consistent PascalCasedAccordionDefinition
andAccordionItemDefinition
.Accordion.accordionItems
property was typed asElement[]
, which required a lot of checking to confirm if the collection actually containsAccordionItem[]
. This PR fixes the property's type to make it easier to work with.This PR also fixes some minor API Extractor warnings generated by the
Accordion
andAccordionItem
modules.