Skip to content

Commit

Permalink
Remove clear button
Browse files Browse the repository at this point in the history
  • Loading branch information
HalvorHaugan committed Dec 6, 2024
1 parent f1a0efd commit a66c37a
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 88 deletions.
7 changes: 7 additions & 0 deletions .changeset/quick-seas-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@navikt/aksel-stylelint": minor
"@navikt/ds-react": minor
"@navikt/ds-css": minor
---

Combobox: Removed clear button, removed tokens `--ac-combobox-clear-icon*`, deprecated props `clearButton`/`clearButtonLabel`.
2 changes: 1 addition & 1 deletion .changeset/strong-carpets-fly.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@navikt/ds-react": minor
---

Combobox: Deprecated props `clearButton` and `clearButtonLabel`, and changed `maxSelected` to number.
Combobox: Changed prop `maxSelected` to number
4 changes: 4 additions & 0 deletions @navikt/aksel-stylelint/src/deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ export const deprecations: DeprecatedList = [
classes: ["navds-list--nested", "navds-list__item-content"],
message: "Removed in v7.1.1",
},
{
classes: ["navds-combobox__button-clear"],
message: "Removed in v7.8.0",
},
];
21 changes: 0 additions & 21 deletions @navikt/core/css/darkside/form/combobox.darkside.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
}
}

.navds-combobox__button-clear svg,
.navds-combobox__button-toggle-list svg,
.navds-combobox__list svg {
width: var(--__axc-combobox-icon-size);
Expand Down Expand Up @@ -203,19 +202,6 @@
}
}

.navds-combobox__button-clear {
border-radius: var(--ax-border-radius-medium);
color: var(--ax-text-subtle);
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
background: none;
border: none;
font-size: 1rem;
padding: 0;
}

.navds-combobox__input::-webkit-search-cancel-button {
display: none;
}
Expand All @@ -231,10 +217,7 @@
border: none;
font-size: 1rem;
padding: 0;
}

.navds-combobox__button-clear,
.navds-combobox__button-toggle-list {
&:hover {
color: var(--ax-text-accent);

Expand Down Expand Up @@ -405,10 +388,6 @@
}

@media (forced-colors: active) {
.navds-combobox__button-clear:hover {
color: highlight;
}

.navds-combobox__wrapper-inner:has(.navds-combobox__input:focus-visible) {
outline-color: highlight;
}
Expand Down
24 changes: 2 additions & 22 deletions @navikt/core/css/form/combobox.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
border-color: var(--a-border-subtle);
}

.navds-combobox__button-clear svg,
.navds-combobox__button-toggle-list svg,
.navds-combobox__list svg {
width: var(--__ac-combobox-icon-size);
Expand Down Expand Up @@ -195,19 +194,6 @@
}
}

.navds-combobox__button-clear {
border-radius: var(--a-border-radius-medium);
color: var(--ac-combobox-clear-icon, var(--a-text-subtle));
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
background: none;
border: none;
font-size: 1rem;
padding: 0;
}

.navds-combobox__input::-webkit-search-cancel-button {
display: none;
}
Expand All @@ -225,14 +211,12 @@
padding: 0;
}

.navds-combobox__button-clear:active:hover,
.navds-combobox__button-toggle-list:active:hover {
color: var(--ac-combobox-clear-icon-active, var(--a-text-action));
color: var(--a-text-action);
}

.navds-combobox__button-clear:hover,
.navds-combobox__button-toggle-list:hover {
color: var(--ac-combobox-clear-icon-hover, var(--a-text-action-selected));
color: var(--a-text-action-selected);
}

.navds-combobox__button-toggle-list:focus-visible {
Expand Down Expand Up @@ -406,10 +390,6 @@
}

@media (forced-colors: active) {
.navds-combobox__button-clear:hover {
color: highlight;
}

.navds-combobox__wrapper-inner:has(.navds-combobox__input:focus-visible) {
outline-color: highlight;
}
Expand Down
3 changes: 0 additions & 3 deletions @navikt/core/css/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,6 @@
"--ac-search-error-border": "--a-border-danger"
},
"combobox": {
"--ac-combobox-clear-icon": "--a-text-subtle",
"--ac-combobox-clear-icon-hover": "--a-text-action-selected",
"--ac-combobox-clear-icon-active": "--a-text-action",
"--ac-combobox-list-bg": "--a-surface-default",
"--ac-combobox-list-text": "--a-text-default",
"--ac-combobox-list-border-color": "--a-border-divider",
Expand Down
12 changes: 6 additions & 6 deletions @navikt/core/react/src/form/combobox/ComboboxWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ const ComboboxWrapper = ({
const wrapperRef = useRef<HTMLDivElement | null>(null);
const [hasFocusWithin, setHasFocusWithin] = useState(false);

function onFocusInsideWrapper(e) {
function onFocusInsideWrapper(event: React.FocusEvent<HTMLDivElement>) {
if (
!wrapperRef.current?.contains(e.relatedTarget) &&
toggleOpenButtonRef?.current !== e.target
!wrapperRef.current?.contains(event.relatedTarget) &&
toggleOpenButtonRef?.current !== event.target
) {
toggleIsListOpen(true);
setHasFocusWithin(true);
}
}

function onBlurWrapper(e) {
if (!wrapperRef.current?.contains(e.relatedTarget)) {
function onBlurWrapper(event: React.FocusEvent<HTMLDivElement>) {
if (!wrapperRef.current?.contains(event.relatedTarget)) {
toggleIsListOpen(false);
setHasFocusWithin(false);
clearInput(e);
clearInput(event);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const InputProvider = ({ children, value: props }: Props) => {
);

const clearInput = useCallback(
(event: React.PointerEvent | React.KeyboardEvent | React.MouseEvent) => {
(event: React.PointerEvent | React.KeyboardEvent | React.FocusEvent) => {
onClear?.(event);
externalOnChange?.("");
setInternalValue("");
Expand Down
27 changes: 4 additions & 23 deletions @navikt/core/react/src/form/combobox/Input/InputController.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable jsx-a11y/no-static-element-interactions */
import cl from "clsx";
import React, { forwardRef } from "react";
import { XMarkIcon } from "@navikt/aksel-icons";
import { useMergeRefs } from "../../../util/hooks";
import { useI18n } from "../../../util/i18n/i18n.context";
import { useFilteredOptionsContext } from "../FilteredOptions/filteredOptionsContext";
import SelectedOptions from "../SelectedOptions/SelectedOptions";
import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
Expand All @@ -28,7 +26,9 @@ export const InputController = forwardRef<
>
>((props, ref) => {
const {
clearButton = true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Remove when prop has been removed from ComboboxProps.
clearButton,
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Remove when prop has been removed from ComboboxProps.
clearButtonLabel,
toggleListButton = true,
inputClassName,
Expand All @@ -37,10 +37,8 @@ export const InputController = forwardRef<
} = props;

const {
clearInput,
focusInput,
inputProps,
value,
size = "medium",
inputRef,
toggleOpenButtonRef,
Expand All @@ -52,11 +50,6 @@ export const InputController = forwardRef<

const mergedInputRef = useMergeRefs(inputRef, ref);

const translate = useI18n(
"Combobox",
clearButtonLabel ? { clear: clearButtonLabel } : undefined,
);

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
<div
Expand Down Expand Up @@ -86,19 +79,7 @@ export const InputController = forwardRef<
/>
</SelectedOptions>
)}
<div>
{value && clearButton && (
<div
onClick={clearInput}
className="navds-combobox__button-clear"
aria-hidden
title={translate("clear")}
>
<XMarkIcon />
</div>
)}
{toggleListButton && <ToggleListButton ref={toggleOpenButtonRef} />}
</div>
{toggleListButton && <ToggleListButton ref={toggleOpenButtonRef} />}
</div>
);
});
4 changes: 2 additions & 2 deletions @navikt/core/react/src/form/combobox/combobox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ Default.argTypes = {
defaultValue: "medium",
control: { type: "radio" },
},
clearButtonLabel: {
control: { type: "text" },
toggleListButton: {
control: { type: "boolean" },
},
};

Expand Down
12 changes: 3 additions & 9 deletions @navikt/core/react/src/form/combobox/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,11 @@ export interface ComboboxProps
*/
allowNewValues?: boolean;
/**
* Adds a button to clear the input value when not empty.
* NB: Will not clear selected values.
* @default true
* @deprecated The clear button will be removed in a future release.
* @deprecated The clear button has been removed. This prop has no effect.
*/
clearButton?: boolean;
/**
* Custom name for the clear button. Requires `clearButton` to be `true`.
*
* @default "Tøm"
* @deprecated The clear button will be removed in a future release.
* @deprecated The clear button has been removed. This prop has no effect.
*/
clearButtonLabel?: string;
/**
Expand Down Expand Up @@ -104,7 +98,7 @@ export interface ComboboxProps
* @param event
*/
onClear?: (
event: React.PointerEvent | React.KeyboardEvent | React.MouseEvent,
event: React.PointerEvent | React.KeyboardEvent | React.FocusEvent,
) => void;
/**
* Callback function triggered whenever an option is selected or de-selected.
Expand Down

0 comments on commit a66c37a

Please sign in to comment.