Skip to content

Commit

Permalink
PAY-3233 Disable reset on select field for AM/PM (#9296)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickyrombo authored Jul 30, 2024
1 parent bcd8e13 commit 8b92b23
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/harmony/src/components/select/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(function Select(
controlledProp: selectionProp,
defaultValue: null,
stateName: 'selection',
componentName: 'FilterButton'
componentName: 'Select'
})

// TODO: implement filtering
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SelectInputProps } from './types'
export const SelectInput = forwardRef<HTMLInputElement, SelectInputProps>(
function Select(props, ref) {
const {
disableReset,
value: valueProp,
children,
onChange,
Expand Down Expand Up @@ -47,7 +48,7 @@ export const SelectInput = forwardRef<HTMLInputElement, SelectInputProps>(
(e) => {
e.stopPropagation()
e.preventDefault()
if (value !== null) {
if (value !== null && !disableReset) {
setValue(null)
// @ts-ignore
onChange?.(null)
Expand All @@ -56,7 +57,7 @@ export const SelectInput = forwardRef<HTMLInputElement, SelectInputProps>(
setIsOpen((isOpen: boolean) => !isOpen)
}
},
[value, setIsOpen, setValue, onChange, onReset]
[value, setIsOpen, setValue, onChange, onReset, disableReset]
)

useEffect(() => {
Expand All @@ -81,7 +82,11 @@ export const SelectInput = forwardRef<HTMLInputElement, SelectInputProps>(
<TextInput
{...inputProps}
onClick={handleClick}
endIcon={value !== null ? IconCloseAlt : IconCaretDown || undefined}
endIcon={
value !== null && !disableReset
? IconCloseAlt
: IconCaretDown || undefined
}
IconProps={{ onClick: handleClickIcon }}
aria-haspopup='listbox'
aria-expanded={isOpen}
Expand Down
2 changes: 2 additions & 0 deletions packages/harmony/src/components/select/SelectInput/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ export type SelectInputProps = Omit<TextInputProps, 'children' | 'value'> & {
* This will override the default behavior of toggling isOpen
*/
onClick?: () => void

disableReset?: boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const ScheduledReleaseDateField = () => {
{ value: 'AM', label: 'AM' },
{ value: 'PM', label: 'PM' }
]}
disableReset={true}
/>
</Box>
</Flex>
Expand Down

0 comments on commit 8b92b23

Please sign in to comment.