Skip to content

Commit c853b01

Browse files
committed
feat: enhance SegmentedControl by adding unique input IDs and improving accessibility with memoized IDs
1 parent 502fbf5 commit c853b01

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/Common/SegmentedControl/Segment.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { ReactElement } from 'react'
1+
import { ReactElement, useMemo } from 'react'
22

33
import { Tooltip } from '@Common/Tooltip'
44
import { Icon } from '@Shared/Components'
55
import { ComponentSizeType } from '@Shared/constants'
6+
import { getUniqueId } from '@Shared/Helpers'
67

78
import { ConditionalWrap } from '../Helper'
89
import { COMPONENT_SIZE_TO_ICON_CLASS_MAP, COMPONENT_SIZE_TO_SEGMENT_CLASS_MAP } from './constants'
@@ -24,6 +25,8 @@ const Segment = ({
2425
size,
2526
disabled,
2627
}: SegmentProps) => {
28+
const inputId = useMemo(getUniqueId, [])
29+
2730
const { value, icon, isError, label, tooltipProps, ariaLabel } = segment
2831
const handleChange = () => {
2932
onChange(segment)
@@ -32,13 +35,13 @@ const Segment = ({
3235
return (
3336
<ConditionalWrap key={value} condition={!!tooltipProps?.content} wrap={wrapWithTooltip(tooltipProps)}>
3437
<div
35-
className={`dc__position-rel dc__text-center ${fullWidth ? 'flex-grow-1' : ''}`}
38+
className={`dc__position-rel dc__text-center dc__no-shrink ${fullWidth ? 'flex-grow-1' : ''}`}
3639
ref={selectedSegmentRef}
3740
>
3841
<input
3942
type="radio"
4043
value={value}
41-
id={`${name}-${value}`}
44+
id={inputId}
4245
name={name}
4346
onChange={handleChange}
4447
checked={isSelected}
@@ -47,7 +50,7 @@ const Segment = ({
4750
/>
4851

4952
<label
50-
htmlFor={`${name}-${value}`}
53+
htmlFor={inputId}
5154
className={`pointer m-0 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]}`}
5255
aria-label={ariaLabel}
5356
>

src/Shared/Components/AppStatusModal/AppStatusContent.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ const AppStatusContent = ({
5151
}
5252

5353
const getNodeMessage = (nodeDetails: Node) => {
54+
const resourceKey = getResourceKey(nodeDetails)
55+
5456
if (
5557
appDetails.resourceTree?.resourcesSyncResult &&
5658
// eslint-disable-next-line no-prototype-builtins
57-
appDetails.resourceTree.resourcesSyncResult.hasOwnProperty(getResourceKey(nodeDetails))
59+
appDetails.resourceTree.resourcesSyncResult.hasOwnProperty(resourceKey)
5860
) {
59-
return appDetails.resourceTree.resourcesSyncResult[getResourceKey(nodeDetails)]
61+
return appDetails.resourceTree.resourcesSyncResult[resourceKey]
6062
}
6163
return ''
6264
}

0 commit comments

Comments
 (0)