Skip to content

Commit 0ca413e

Browse files
committed
feat: update SegmentedControl to use unique name prop and improve key handling in StatusFilterButtonComponent
1 parent 64cc114 commit 0ca413e

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/Common/SegmentedControl/Segment.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ const Segment = ({
5454
htmlFor={inputId}
5555
layout
5656
className={`pointer m-0 dc__position-rel flex ${!fullWidth ? 'left' : ''} dc__gap-4 br-4 segmented-control__segment segmented-control__segment--${size} ${isSelected ? 'fw-6 segmented-control__segment--selected' : 'fw-4'} ${segment.isError ? 'cr-5' : 'cn-9'} ${disabled ? 'cursor-not-allowed' : ''} ${COMPONENT_SIZE_TO_SEGMENT_CLASS_MAP[size]}`}
57-
whileTap={{ scale: 0.95 }}
5857
key={inputId}
5958
aria-label={ariaLabel}
6059
>
6160
{isSelected && (
6261
<motion.div
63-
layoutId="active-segment-control"
62+
layoutId={`active-segment-control-${name}`}
6463
className="dc__position-abs active-mask dc__top-0 dc__left-0 dc__right-0 dc__bottom-0 bg__primary br-4"
6564
/>
6665
)}

src/Common/SegmentedControl/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export type SegmentedControlProps = {
5656
* List of segments to be displayed
5757
*/
5858
segments: SegmentType[]
59+
/**
60+
* Please make sure this is unique
61+
*/
5962
name: string
6063
size?: Extract<ComponentSizeType, ComponentSizeType.xs | ComponentSizeType.small | ComponentSizeType.medium>
6164
fullWidth?: boolean

src/Shared/Components/CICDHistory/StatusFilterButtonComponent.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { useEffect, useState } from 'react'
17+
import { useEffect, useRef, useState } from 'react'
1818

1919
import { ReactComponent as ICCaretDown } from '@Icons/ic-caret-down.svg'
2020
import { SegmentType } from '@Common/SegmentedControl/types'
2121
import { ComponentSizeType } from '@Shared/constants'
22+
import { getUniqueId } from '@Shared/Helpers'
2223

2324
import { PopupMenu, SegmentedControl } from '../../../Common'
2425
import { StatusFilterButtonType } from './types'
@@ -32,6 +33,8 @@ export const StatusFilterButtonComponent = ({
3233
handleFilterClick,
3334
maxInlineFiltersCount = 0,
3435
}: StatusFilterButtonType) => {
36+
const segmentControlName = useRef(getUniqueId())
37+
3538
// STATES
3639
const [overflowFilterIndex, setOverflowFilterIndex] = useState(0)
3740

@@ -104,19 +107,13 @@ export const StatusFilterButtonComponent = ({
104107

105108
const segmentValue = segments.find(({ value }) => value === selectedTab)?.value || null
106109

107-
const segmentControlKey = inlineFilters.reduce<string>(
108-
(acc, inlineFilter) => `${acc}-${inlineFilter.status}`,
109-
`${allResourceKindFilter.status}`,
110-
)
111-
112110
return (
113111
<div className="flexbox status-filter__container">
114112
<SegmentedControl
115-
key={segmentControlKey}
116113
segments={segments}
117114
value={segmentValue}
118115
onChange={handleInlineFilterClick}
119-
name="status-filter-button"
116+
name={segmentControlName.current}
120117
size={ComponentSizeType.small}
121118
/>
122119

0 commit comments

Comments
 (0)