-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added selectionMode parameter to support single row selection (#324)
Co-authored-by: Michael Beckemeyer <m.beckemeyer@conterra.de>
- Loading branch information
1 parent
b5bb7a1
commit fbd12d6
Showing
15 changed files
with
313 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@open-pioneer/result-list": minor | ||
--- | ||
|
||
Added the possibility to configure single or multi row selection mode. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,52 @@ | ||
// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer) | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { Checkbox, Radio, Tooltip, chakra } from "@open-pioneer/chakra-integration"; | ||
import { ChangeEvent, useId, useMemo } from "react"; | ||
|
||
export interface SelectComponentProps { | ||
mode?: "checkbox" | "radio"; | ||
toolTipLabel?: string; | ||
|
||
className?: string; | ||
"aria-label"?: string; | ||
isIndeterminate?: boolean; | ||
isChecked?: boolean; | ||
isDisabled?: boolean; | ||
onChange?: (event: ChangeEvent<HTMLInputElement>) => void; | ||
} | ||
|
||
export function SelectComponent({ | ||
mode = "checkbox", | ||
toolTipLabel, | ||
...props | ||
}: SelectComponentProps) { | ||
const Component = mode === "checkbox" ? Checkbox : SelectRadio; | ||
const renderedComponent = useMemo(() => { | ||
return <Component {...props} />; | ||
}, [Component, props]); | ||
if (!toolTipLabel) { | ||
return renderedComponent; | ||
} | ||
|
||
return ( | ||
<Tooltip label={toolTipLabel} placement="right" closeOnClick={false}> | ||
<chakra.span | ||
/* | ||
wrap into span to fix tooltip around checkbox, see https://github.com/chakra-ui/chakra-ui/issues/6353 | ||
not using "shouldWrapChildren" because that also introduces a _focusable_ span (we only want the checkbox) | ||
*/ | ||
> | ||
{renderedComponent} | ||
</chakra.span> | ||
</Tooltip> | ||
); | ||
} | ||
|
||
function SelectRadio(props: Omit<SelectComponentProps, "mode">) { | ||
const id = useId(); | ||
const { isIndeterminate, ...rest } = props; | ||
void isIndeterminate; // ignored, not supported by radio button | ||
|
||
/** Name seems to be required for screen reader tabbing support. */ | ||
return <Radio name={id} {...rest} />; | ||
} |
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
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
Oops, something went wrong.