Skip to content

Commit

Permalink
add console warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
OskiTheCoder committed Nov 14, 2023
1 parent e13e0b8 commit 33b5925
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions easy-ui-react/src/InputField/InputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useInputField } from "./useInputField";
import styles from "./InputField.module.scss";
import {
getElementType,
logWarningForMissingAriaLabel,
logWarningsForInvalidPropConfiguration,
} from "./utilities";

Expand Down Expand Up @@ -106,6 +107,7 @@ export function InputField(props: InputFieldProps) {
validationState = "valid",
isLabelEmphasized = false,
autoFocus = false,
"aria-label": ariaLabel,
label,
errorText,
helperText,
Expand Down Expand Up @@ -135,6 +137,8 @@ export function InputField(props: InputFieldProps) {
definedIconsWithTextarea,
);

logWarningForMissingAriaLabel(label, ariaLabel);

const isPassword = type === "password";
const hasError = validationState === "invalid";
const showErrorText = hasError && errorText;
Expand Down
10 changes: 10 additions & 0 deletions easy-ui-react/src/InputField/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ReactNode } from "react";
import { InputSize } from "./InputField";

/** Small fields need xs icon */
Expand Down Expand Up @@ -28,6 +29,15 @@ export function logWarningsForInvalidPropConfiguration(
}
}

export function logWarningForMissingAriaLabel(
label: ReactNode,
ariaLabel: string | undefined,
) {
if (!label && !ariaLabel) {
console.warn("An aria-label must be provided if omitting `label`");
}
}

export function getElementType(isMultiline: boolean) {
return isMultiline ? "textarea" : "input";
}
4 changes: 4 additions & 0 deletions easy-ui-react/src/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SelectOption } from "./SelectOption";
import { SelectSection } from "./SelectSection";
import { SelectOverlay } from "./SelectOverlay";
import { useTriggerWidth } from "../Menu/useTriggerWidth";
import { logWarningForMissingAriaLabel } from "../InputField/utilities";

export type BaseSelectProps<T> = {
/** Method that is called when the open state of the select field changes. */
Expand Down Expand Up @@ -96,6 +97,7 @@ export function Select<T extends object>(props: SelectProps<T>) {
validationState,
isLabelEmphasized,
size = "md",
"aria-label": ariaLabel,
label,
errorText,
helperText,
Expand All @@ -106,6 +108,8 @@ export function Select<T extends object>(props: SelectProps<T>) {
const triggerRef = React.useRef(null);
const selectState = useSelectState(props);

logWarningForMissingAriaLabel(label, ariaLabel);

const {
labelProps,
valueProps,
Expand Down

0 comments on commit 33b5925

Please sign in to comment.