Skip to content
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

Fix the Select component when allowClear is enabled #793

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions assets/js/src/core/components/select/select.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ export const useStyles = createStyles(({ css, token }, props: StylesProps) => {
}
`,

selectContainerWithClear: css`
&:hover {
.ant-select-arrow {
display: none;
}
}
`,

select: css`
width: ${!isEmptyValue(props.width) ? `${props.width}px` : 'initial'};
Expand Down
12 changes: 10 additions & 2 deletions assets/js/src/core/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ export interface SelectProps extends AntdSelectProps {
width?: number
}

export const Select = forwardRef<RefSelectProps, SelectProps>(({ customIcon, customArrowIcon, mode, status, className, width, ...antdSelectProps }, ref): React.JSX.Element => {
export const Select = forwardRef<RefSelectProps, SelectProps>(({ customIcon, customArrowIcon, mode, status, className, width, allowClear, ...antdSelectProps }, ref): React.JSX.Element => {
const selectRef = useRef<RefSelectProps>(null)

const [isActive, setIsActive] = useState(false)
const [isFocus, setIsFocus] = useState(false)
const [isSelected, setIsSelected] = useState(false)

useImperativeHandle(ref, () => selectRef.current!)

Expand All @@ -41,7 +42,8 @@ export const Select = forwardRef<RefSelectProps, SelectProps>(({ customIcon, cus

const selectContainerClassNames = cn(styles.selectContainer, {
[styles.selectContainerWarning]: isStatusWarning,
[styles.selectContainerError]: isStatusError
[styles.selectContainerError]: isStatusError,
[styles.selectContainerWithClear]: allowClear === true && isSelected
})
const selectClassNames = cn(className, styles.select, {
[styles.selectWithCustomIcon]: withCustomIcon
Expand All @@ -54,6 +56,10 @@ export const Select = forwardRef<RefSelectProps, SelectProps>(({ customIcon, cus

const handleClick = (): void => { setIsActive(!isActive) }

const handleChange = (value: string): void => {
!isEmpty(value) ? setIsSelected(true) : setIsSelected(false)
}

const getSuffixIcon = (): React.JSX.Element => {
const isShowCustomIcon = !isEmpty(customArrowIcon) && isString(customArrowIcon)
const iconToShow = isShowCustomIcon ? customArrowIcon : (isActive ? 'chevron-up' : 'chevron-down')
Expand Down Expand Up @@ -83,10 +89,12 @@ export const Select = forwardRef<RefSelectProps, SelectProps>(({ customIcon, cus
/>
)}
<AntdSelect
allowClear={ allowClear }
className={ selectClassNames }
menuItemSelectedIcon={ getItemSelectedIcon() }
mode={ mode }
onBlur={ () => { setIsFocus(false) } }
onChange={ handleChange }
onDropdownVisibleChange={ handleClick }
onFocus={ () => { setIsFocus(true) } }
ref={ selectRef }
Expand Down

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions public/build/44b37049-db4f-4146-9a7f-9c30ff6aacea/core-dll.js

This file was deleted.

12 changes: 0 additions & 12 deletions public/build/44b37049-db4f-4146-9a7f-9c30ff6aacea/entrypoints.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"entrypoints": {
"main": {
"js": [
"/bundles/pimcorestudioui/build/48593847-76fa-47e4-8014-93645730dcfc/main.js"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bundles/pimcorestudioui/build/48593847-76fa-47e4-8014-93645730dcfc/main.js": "/bundles/pimcorestudioui/build/48593847-76fa-47e4-8014-93645730dcfc/main.js"
}

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions public/build/5ef68380-44fe-45f5-b313-f9c1e78fa12f/core-dll.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/build/5ef68380-44fe-45f5-b313-f9c1e78fa12f/entrypoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"entrypoints": {
"core-dll": {
"css": [
"/bundles/pimcorestudioui/build/5ef68380-44fe-45f5-b313-f9c1e78fa12f/core-dll.css"
],
"js": [
"/bundles/pimcorestudioui/build/5ef68380-44fe-45f5-b313-f9c1e78fa12f/core-dll.js"
]
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"entrypoints": {
"vendor": {
"js": [
"/bundles/pimcorestudioui/build/6c0cfd99-8b84-41cf-afdc-dd21bb54dfd4/vendor.js"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bundles/pimcorestudioui/build/6c0cfd99-8b84-41cf-afdc-dd21bb54dfd4/vendor.js": "/bundles/pimcorestudioui/build/6c0cfd99-8b84-41cf-afdc-dd21bb54dfd4/vendor.js"
}

This file was deleted.

This file was deleted.

Loading