Skip to content

Commit

Permalink
fix: Add useselectcard
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel.carrera committed Sep 5, 2023
1 parent 9833e6a commit 9311d96
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion modules/react/collection/lib/useListItemRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const useListItemRegister = createElemPropsHook(useListModel)(
disabled: elemProps.disabled || state.nonInteractiveIds.includes(localId) ? true : undefined,
item: null, // remove `item` from prop list
virtual: null, // remove `virtual` from prop list
'aria-setsize': state.items.length || elemProps.virtual?.size,
'aria-setsize': elemProps.virtual?.size,
'aria-posinset': elemProps.virtual ? elemProps.item!.index + 1 : undefined,
style,
id: slugify(`${state.id}-${localId}`),
Expand Down
2 changes: 1 addition & 1 deletion modules/react/combobox/lib/useComboboxModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const useComboboxModel = createModelHook({
defaultConfig: {
...useInputModel.defaultConfig,
...useMenuModel.defaultConfig,
shouldVirtualize: true,
},

requiredConfig: {
Expand All @@ -54,7 +55,6 @@ export const useComboboxModel = createModelHook({

const menu = useMenuModel(
useMenuModel.mergeConfig(config, {
shouldVirtualize: true,
onSelect({id}) {
dispatchInputEvent(menu.state.targetRef.current, id);
},
Expand Down
15 changes: 14 additions & 1 deletion modules/react/select/lib/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {caretDownSmallIcon} from '@workday/canvas-system-icons-web';
import {useSelectModel, useSelectItem} from './hooks';
import {useSelectInput} from './hooks/useSelectInput';
import {CanvasSystemIcon} from '@workday/design-assets-types';
import {useSelectCard} from './hooks/useSelectCard';

export interface SelectInputProps extends ExtractProps<typeof TextInput> {
/**
Expand Down Expand Up @@ -63,6 +64,17 @@ export const SelectItem = createSubcomponent('li')({
);
});

export const SelectCard = createSubcomponent('div')({
modelHook: useSelectModel,
elemPropsHook: useSelectCard,
})<ExtractProps<typeof Combobox.Menu.Card>>(({children, ...elemProps}, Element) => {
return (
<Combobox.Menu.Card as={Element} {...elemProps}>
{children}
</Combobox.Menu.Card>
);
});

export interface SelectProps extends Themeable, ExtractProps<typeof Combobox> {}
/**
* Use `Select` to allow users to choose an option from a list or type characters to select a matching option.
Expand Down Expand Up @@ -117,6 +129,7 @@ export const Select = createContainer()({
Popper: Combobox.Menu.Popper,
/**
* `Select.Card` renders a {@link ComboboxCard Combobox.Card}. You have access to all `Card` props.
* The card will be the width of the select input.
* ```tsx
* <Select item={options}>
* <Select.Input id="matching-formfield-inputId" onChange={(event) => handleChange(event)}>
Expand All @@ -128,7 +141,7 @@ export const Select = createContainer()({
* </Select>
* ```
*/
Card: Combobox.Menu.Card,
Card: SelectCard,
/**
* `Select.List` renders a {@link ComboboxMenuList Combobox.Menu.List}. You have access to all `ListBox` props.
* ```tsx
Expand Down
11 changes: 11 additions & 0 deletions modules/react/select/lib/hooks/useSelectCard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {createElemPropsHook} from '@workday/canvas-kit-react/common';
import {useSelectModel} from './useSelectModel';

/**
* Set the width of the menu card to the input width
*/
export const useSelectCard = createElemPropsHook(useSelectModel)(model => {
return {
width: model.state.width,
} as const;
});
2 changes: 2 additions & 0 deletions modules/react/select/lib/hooks/useSelectModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import {useComboboxModel} from '@workday/canvas-kit-react/combobox';
export const useSelectModel = createModelHook({
defaultConfig: {
...useComboboxModel.defaultConfig,
shouldVirtualize: false,
},
requiredConfig: {
...useComboboxModel.requiredConfig,
},
contextOverride: useComboboxModel.Context,
})(config => {
console.log(config);
const model = useComboboxModel(config);
return model;
});

0 comments on commit 9311d96

Please sign in to comment.