New Tabs component implementation#2061
Merged
GomezIvann merged 30 commits intomasterfrom Sep 17, 2024
Merged
Conversation
…o Mil4n0r/new_tabs_implementation
Tabs component implementation
Collaborator
Author
|
Good job @Jialecl. Changes look legit. The only thing to improve I can think of would be to improve the typings so that only legacy behavior or new behavior are allowed, not both at once. However, I am not sure if that is worth it taking into account that the legacy behavior will eventually be removed. Let me know what you guys think @Jialecl @GomezIvann. |
…dxc-technology/halstack-react into Mil4n0r/new_tabs_implementation
GomezIvann
suggested changes
Sep 16, 2024
GomezIvann
reviewed
Sep 17, 2024
Collaborator
GomezIvann
left a comment
There was a problem hiding this comment.
Just a general thought. There are too many variables depending on each other (because of useMemo) inside Tabs.tsx which are only use once or twice. For example:
hasActiveChild,initialActiveTabLabelcan be transformed into an initialization function inside theuseStateofactiveTabLabel:
const childrenArray: ReactElement<TabProps>[] = useMemo(
() => Children.toArray(children) as ReactElement<TabProps>[],
[children]
);
const hasLabelAndIcon = useMemo(
() => childrenArray.some((child) => isValidElement(child) && child.props.icon && child.props.label),
[childrenArray]
);
const [activeTabLabel, setActiveTabLabel] = useState(() => {
const hasActiveChild = childrenArray.some(
(child) => isValidElement(child) && (child.props.active || child.props.defaultActive) && !child.props.disabled
);
const initialActiveTab = hasActiveChild
? childrenArray.find(
(child) => isValidElement(child) && (child.props.active || child.props.defaultActive) && !child.props.disabled
)
: childrenArray.find((child) => isValidElement(child) && !child.props.disabled);
return isValidElement(initialActiveTab) ? initialActiveTab.props.label : "";
});
- You can directly pass a function to
aria-disabledfromActiveIndicatorin order to remove another const (isActiveIndicatorDisabled).
aria-disabled={childrenArray.some((child) =>
isValidElement(child) ? activeTabLabel === child.props.label && child.props.disabled : false
)}
Since you are already memorizing the value of childrenArray, all this changes make sense and don't trigger rerenders.
GomezIvann
approved these changes
Sep 17, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
(Check off all the items before submitting)
/libdirectory./websiteas needed.Description
Current
DxcTabsAPI is confusing, as it is expected to work in a similar way as DxcNavTabs, but it does not provide Compound Components, so we have no access to onClick/onHover events separately for each Tab.For consistency purposes and easier implementation of the wrappers required in Halstack Studio and UXPin, it is convenient to redo it.
For now, we are maintaining the old API available to prevent adding breaking changes, however, those props will be marked as LEGACY/DEPRECATED to not encourage using them in the future (and eventually, removing them).