-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(select): max menu width * feat(select): select custom option with tooltip * chore(select): code improvement on custom option --------- Co-authored-by: Thrasos Kafasis <[email protected]>
- Loading branch information
1 parent
bbfbbc8
commit 1c7c71c
Showing
7 changed files
with
125 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
32 changes: 32 additions & 0 deletions
32
src/components/FormElements/Select/components/CustomOption.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { FC, useEffect, useRef, useState } from "react"; | ||
import { components, OptionProps } from "react-select"; | ||
import { CustomOption } from "../types"; | ||
import Tooltip from "../../../Tooltip/Tooltip"; | ||
|
||
const CustomOptionComponent: FC<OptionProps<CustomOption>> = (props) => { | ||
const [isOverflowActive, setIsOverflowActive] = useState(false); | ||
const optionRef = useRef<HTMLDivElement>(null); | ||
|
||
const { isDisabled, data } = props; | ||
const { label } = data; | ||
const isTooltipDisabled = isDisabled || !isOverflowActive; | ||
|
||
useEffect(() => { | ||
if (optionRef.current) { | ||
const hasOverflow = optionRef.current.scrollWidth > optionRef.current.clientWidth; | ||
setIsOverflowActive(hasOverflow); | ||
} | ||
}, [props.label]); | ||
|
||
return ( | ||
<components.Option {...props}> | ||
<Tooltip content={label} disabled={isTooltipDisabled}> | ||
<div className="custom-option" ref={optionRef}> | ||
{label} | ||
</div> | ||
</Tooltip> | ||
</components.Option> | ||
); | ||
}; | ||
|
||
export default CustomOptionComponent; |
This file contains 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
This file contains 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
This file contains 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