DOP-3564: (latest) flag (#19)

This commit is contained in:
mmeigs 2023-03-21 12:04:02 -04:00 committed by GitHub
parent 82133beda4
commit bee65e86ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 5 deletions

View File

@ -3,18 +3,18 @@ import { StyledLi, StyledOptionText, StyledPlaceholder } from './styled.elements
import Checkmark from './CheckmarkSvg';
import { OptionProps } from './types';
export const Option = ({ option, selected, onClick }: OptionProps) => {
export const Option = ({ option, value, selected, onClick }: OptionProps) => {
const KEY_ENTER = 'ENTER';
const KEY_SPACE = 'SPACE';
const handleKeyPress = (event: React.KeyboardEvent) => {
if (event.key === KEY_ENTER || event.key === KEY_SPACE) {
onClick(option);
onClick(value);
}
};
return (
<StyledLi onClick={() => onClick(option)} onKeyPress={handleKeyPress} selected={selected}>
<StyledLi onClick={() => onClick(value)} onKeyPress={handleKeyPress} selected={selected}>
{selected ? <Checkmark /> : <StyledPlaceholder />}
<StyledOptionText>{option}</StyledOptionText>
</StyledLi>

View File

@ -59,7 +59,8 @@ const VersionSelectorComponent = ({
<Option
key={`option-${i}`}
selected={i === selectedIdx}
option={option}
value={option}
option={`${option}${i === resourceVersions.length - 1 ? ' (latest)' : ''}`}
onClick={option => handleClick(i, option)}
/>
))}

View File

@ -11,6 +11,7 @@ export interface VersionSelectorProps {
export interface OptionProps {
option: string;
value: string;
selected: boolean;
onClick: (option: string) => void;
}

View File

@ -107,7 +107,7 @@ exports[`VersionSelector should correctly render VersionSelector 1`] = `
<span
class="sc-jrsJWt hDLwjI"
>
2023-01-01
2023-01-01 (latest)
</span>
</li>
</ul>