Skip to content

Commit

Permalink
Fix boolean attributes handling in react components (#106)
Browse files Browse the repository at this point in the history
* Fix boolean attributes handling in react components

* Prettify

---------

Co-authored-by: Frédéric Collonval <fcollonval@users.noreply.github.com>
  • Loading branch information
fcollonval and fcollonval authored Jun 17, 2024
1 parent aa84342 commit a336933
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/react-components/lib/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ export const Button = forwardRef((props, forwardedRef) => {
autofocus,
formnovalidate,
defaultSlottedContent,
disabled,
required,
...filteredProps
} = props;

/** Properties - run whenever a property has changed */
useProperties(ref, 'autofocus', props.autofocus);
useProperties(ref, 'formnovalidate', props.formnovalidate);
useProperties(ref, 'defaultSlottedContent', props.defaultSlottedContent);
useProperties(ref, 'disabled', props.disabled);
useProperties(ref, 'required', props.required);

/** Methods - uses `useImperativeHandle` hook to pass ref to component */
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
Expand Down
13 changes: 12 additions & 1 deletion packages/react-components/lib/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@ provideJupyterDesignSystem().register(jpCheckbox());

export const Checkbox = forwardRef((props, forwardedRef) => {
const ref = useRef(null);
const { readonly, readOnly, indeterminate, ...filteredProps } = props;
const {
readonly,
readOnly,
indeterminate,
checked,
disabled,
required,
...filteredProps
} = props;

/** Event listeners - run once */
useEventListener(ref, 'change', props.onChange);

/** Properties - run whenever a property has changed */
useProperties(ref, 'readOnly', props.readOnly);
useProperties(ref, 'indeterminate', props.indeterminate);
useProperties(ref, 'checked', props.checked);
useProperties(ref, 'disabled', props.disabled);
useProperties(ref, 'required', props.required);

/** Methods - uses `useImperativeHandle` hook to pass ref to component */
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
Expand Down
2 changes: 2 additions & 0 deletions packages/react-components/lib/Combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const Combobox = forwardRef((props, forwardedRef) => {
disabled,
selectedIndex,
selectedOptions,
required,
...filteredProps
} = props;

Expand All @@ -44,6 +45,7 @@ export const Combobox = forwardRef((props, forwardedRef) => {
useProperties(ref, 'disabled', props.disabled);
useProperties(ref, 'selectedIndex', props.selectedIndex);
useProperties(ref, 'selectedOptions', props.selectedOptions);
useProperties(ref, 'required', props.required);

/** Methods - uses `useImperativeHandle` hook to pass ref to component */
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
Expand Down
5 changes: 4 additions & 1 deletion packages/react-components/lib/DateField.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ provideJupyterDesignSystem().register(jpDateField());

export const DateField = forwardRef((props, forwardedRef) => {
const ref = useRef(null);
const { autofocus, step, max, min, ...filteredProps } = props;
const { autofocus, step, max, min, disabled, required, ...filteredProps } =
props;

/** Event listeners - run once */
useEventListener(ref, 'input', props.onInput);
Expand All @@ -24,6 +25,8 @@ export const DateField = forwardRef((props, forwardedRef) => {
useProperties(ref, 'step', props.step);
useProperties(ref, 'max', props.max);
useProperties(ref, 'min', props.min);
useProperties(ref, 'disabled', props.disabled);
useProperties(ref, 'required', props.required);

/** Methods - uses `useImperativeHandle` hook to pass ref to component */
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
Expand Down
4 changes: 4 additions & 0 deletions packages/react-components/lib/NumberField.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const NumberField = forwardRef((props, forwardedRef) => {
step,
max,
min,
disabled,
required,
...filteredProps
} = props;

Expand All @@ -43,6 +45,8 @@ export const NumberField = forwardRef((props, forwardedRef) => {
useProperties(ref, 'step', props.step);
useProperties(ref, 'max', props.max);
useProperties(ref, 'min', props.min);
useProperties(ref, 'disabled', props.disabled);
useProperties(ref, 'required', props.required);

/** Methods - uses `useImperativeHandle` hook to pass ref to component */
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
Expand Down
13 changes: 12 additions & 1 deletion packages/react-components/lib/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@ provideJupyterDesignSystem().register(jpRadio());

export const Radio = forwardRef((props, forwardedRef) => {
const ref = useRef(null);
const { readonly, readOnly, name, ...filteredProps } = props;
const {
readonly,
readOnly,
name,
checked,
disabled,
required,
...filteredProps
} = props;

/** Event listeners - run once */
useEventListener(ref, 'change', props.onChange);

/** Properties - run whenever a property has changed */
useProperties(ref, 'readOnly', props.readOnly);
useProperties(ref, 'name', props.name);
useProperties(ref, 'checked', props.checked);
useProperties(ref, 'disabled', props.disabled);
useProperties(ref, 'required', props.required);

/** Methods - uses `useImperativeHandle` hook to pass ref to component */
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
Expand Down
4 changes: 4 additions & 0 deletions packages/react-components/lib/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const Search = forwardRef((props, forwardedRef) => {
minlength,
size,
spellcheck,
disabled,
required,
...filteredProps
} = props;

Expand All @@ -36,6 +38,8 @@ export const Search = forwardRef((props, forwardedRef) => {
useProperties(ref, 'minlength', props.minlength);
useProperties(ref, 'size', props.size);
useProperties(ref, 'spellcheck', props.spellcheck);
useProperties(ref, 'disabled', props.disabled);
useProperties(ref, 'required', props.required);

/** Methods - uses `useImperativeHandle` hook to pass ref to component */
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
Expand Down
2 changes: 2 additions & 0 deletions packages/react-components/lib/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const Select = forwardRef((props, forwardedRef) => {
disabled,
selectedIndex,
selectedOptions,
required,
...filteredProps
} = props;

Expand All @@ -43,6 +44,7 @@ export const Select = forwardRef((props, forwardedRef) => {
useProperties(ref, 'disabled', props.disabled);
useProperties(ref, 'selectedIndex', props.selectedIndex);
useProperties(ref, 'selectedOptions', props.selectedOptions);
useProperties(ref, 'required', props.required);

/** Methods - uses `useImperativeHandle` hook to pass ref to component */
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
Expand Down
4 changes: 4 additions & 0 deletions packages/react-components/lib/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const Slider = forwardRef((props, forwardedRef) => {
min,
max,
step,
disabled,
required,
...filteredProps
} = props;

Expand All @@ -33,6 +35,8 @@ export const Slider = forwardRef((props, forwardedRef) => {
useProperties(ref, 'min', props.min);
useProperties(ref, 'max', props.max);
useProperties(ref, 'step', props.step);
useProperties(ref, 'disabled', props.disabled);
useProperties(ref, 'required', props.required);

/** Methods - uses `useImperativeHandle` hook to pass ref to component */
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
Expand Down
6 changes: 5 additions & 1 deletion packages/react-components/lib/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ provideJupyterDesignSystem().register(jpSwitch());

export const Switch = forwardRef((props, forwardedRef) => {
const ref = useRef(null);
const { readonly, readOnly, ...filteredProps } = props;
const { readonly, readOnly, checked, disabled, required, ...filteredProps } =
props;

/** Event listeners - run once */
useEventListener(ref, 'change', props.onChange);

/** Properties - run whenever a property has changed */
useProperties(ref, 'readOnly', props.readOnly);
useProperties(ref, 'checked', props.checked);
useProperties(ref, 'disabled', props.disabled);
useProperties(ref, 'required', props.required);

/** Methods - uses `useImperativeHandle` hook to pass ref to component */
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
Expand Down
4 changes: 4 additions & 0 deletions packages/react-components/lib/TextArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const TextArea = forwardRef((props, forwardedRef) => {
cols,
rows,
spellcheck,
disabled,
required,
...filteredProps
} = props;

Expand All @@ -42,6 +44,8 @@ export const TextArea = forwardRef((props, forwardedRef) => {
useProperties(ref, 'cols', props.cols);
useProperties(ref, 'rows', props.rows);
useProperties(ref, 'spellcheck', props.spellcheck);
useProperties(ref, 'disabled', props.disabled);
useProperties(ref, 'required', props.required);

/** Methods - uses `useImperativeHandle` hook to pass ref to component */
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
Expand Down
4 changes: 4 additions & 0 deletions packages/react-components/lib/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const TextField = forwardRef((props, forwardedRef) => {
minlength,
size,
spellcheck,
disabled,
required,
...filteredProps
} = props;

Expand All @@ -40,6 +42,8 @@ export const TextField = forwardRef((props, forwardedRef) => {
useProperties(ref, 'minlength', props.minlength);
useProperties(ref, 'size', props.size);
useProperties(ref, 'spellcheck', props.spellcheck);
useProperties(ref, 'disabled', props.disabled);
useProperties(ref, 'required', props.required);

/** Methods - uses `useImperativeHandle` hook to pass ref to component */
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
Expand Down
3 changes: 0 additions & 3 deletions packages/react-components/lib/TreeItem.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ export interface TreeItemProps
/** When true, the control will be immutable by user interaction. See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled | disabled HTML attribute} for more information. */
disabled?: TreeItemElement['disabled'];

/** Whether the tree is nested */
isNestedItem?: TreeItemElement['isNestedItem'];

/** Fires a custom 'expanded-change' event when the expanded state changes */
onExpand?: (event: CustomEvent) => void;

Expand Down
4 changes: 1 addition & 3 deletions packages/react-components/lib/TreeItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ provideJupyterDesignSystem().register(jpTreeItem());

export const TreeItem = forwardRef((props, forwardedRef) => {
const ref = useRef(null);
const { expanded, selected, disabled, isNestedItem, ...filteredProps } =
props;
const { expanded, selected, disabled, ...filteredProps } = props;

/** Event listeners - run once */
useEventListener(ref, 'expanded-change', props.onExpand);
Expand All @@ -24,7 +23,6 @@ export const TreeItem = forwardRef((props, forwardedRef) => {
useProperties(ref, 'expanded', props.expanded);
useProperties(ref, 'selected', props.selected);
useProperties(ref, 'disabled', props.disabled);
useProperties(ref, 'isNestedItem', props.isNestedItem);

/** Methods - uses `useImperativeHandle` hook to pass ref to component */
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
Expand Down

0 comments on commit a336933

Please sign in to comment.