Skip to content

Commit

Permalink
fix: select placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
abelflopes committed Jul 5, 2024
1 parent 8b92f04 commit c98a1b5
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 36 deletions.
47 changes: 20 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions packages/components/form-field/src/styles/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@mixin form-field-container {
@include wrapper;

background: theme.get-color(neutral-light-1);
}

Expand All @@ -26,6 +27,10 @@
}
}

@mixin placeholder {
color: theme.get-color(neutral-dark-1);
}

@mixin form-field-input {
@include spacing;
@include text.text-base;
Expand All @@ -39,12 +44,12 @@

// TODO: focus mixin
outline: solid theme.get-css-var(spacing, border) transparent;
transition-property: outline, outline-offset;
transition-duration: 0.3s;
transition-property: outline, outline-offset;
transition-timing-function: ease;

&::placeholder {
color: theme.get-color(neutral-dark-1);
@include placeholder;
}

&:disabled {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ exports[`snapshot Select renders correctly 1`] = `
onFocus={[Function]}
role="button"
tabIndex={0}
/>,
>
<span
className="placeholder"
/>
</div>,
]
`;
5 changes: 4 additions & 1 deletion packages/components/select/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SelectContext, type SelectContextProps } from "./context";
* @returns a React element
*/

// eslint-disable-next-line max-lines-per-function -- TODO: fix
const Select = ({
skin = "default",
placeholder,
Expand Down Expand Up @@ -177,7 +178,9 @@ const Select = ({
onFocus?.(e);
}}>
{selectedValuesList.length > 0 && selectedValuesList.join(", ")}
{selectedValuesList.length === 0 && placeholder}
{selectedValuesList.length === 0 && (
<span className={styles.placeholder}>{placeholder}</span>
)}
</div>

<Dropdown
Expand Down
4 changes: 4 additions & 0 deletions packages/components/select/src/styles/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@
.search_input {
outline: none !important;
}

.placeholder {
@include form-field.placeholder;
}
2 changes: 1 addition & 1 deletion packages/components/select/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type InputProps } from "@react-ck/input";
import { type MenuItemProps } from "@react-ck/provisional";

export type UserValue = string | string[];
export type UserValue = string | string[] | undefined;

export type SelectedValues = string[];

Expand Down
2 changes: 1 addition & 1 deletion packages/components/select/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "./types";

export const valueAsArray = (value: UserValue): SelectedValues =>
value instanceof Array ? value : [value];
value ? (value instanceof Array ? value : [value]) : [];

export const getChildrenData = (children: React.ReactNode): SelectChildrenData[] =>
getChildrenListWithoutFragments(children).map<SelectChildrenData>((i) => {
Expand Down
4 changes: 1 addition & 3 deletions packages/docs/stories/src/select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ const args: SelectProps = {
children: (
<>
<Select.Option value="Apple" disabled />
<Select.Option value="bnn" disabled selected>
Banana
</Select.Option>
<Select.Option value="bnn">Banana</Select.Option>
<Select.Option value="orange">Orange</Select.Option>
<Select.Option value="lemon">Lemon</Select.Option>
<h1>Exotic</h1>
Expand Down

0 comments on commit c98a1b5

Please sign in to comment.