Skip to content

Commit

Permalink
move tag-container outside select-button
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank99 committed Nov 18, 2024
1 parent 0d9927f commit 880d4f8
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 53 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-numbers-yawn-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': patch
---

`<Select multiple>` now renders the tag container outside the select-button. While this shouldn't make a noticeable difference in most cases, it might affect the use of `selectedItemRenderer`.
29 changes: 29 additions & 0 deletions .changeset/fresh-numbers-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
'@itwin/itwinui-css': major
---

Multi-select with now requires the tag-container to be rendered outside the select-button, and also requires an additional `data-iui-multi` attribute on the select-button.

<details>
<summary>Diff</summary>

```diff
<div class='iui-input-with-icon'>
<div
role='combobox'
tabindex='0'
class='iui-select-button iui-field'
+ data-iui-multi
>
- <span class='iui-content'>
- <div class='iui-select-tag-container'>…</div>
- </span>
</div>
<svg class='iui-end-icon'>…</svg>
+ <span class='iui-content'>
+ <div class='iui-select-tag-container'>…</div>
+ </span>
</div>
```

</details>
67 changes: 33 additions & 34 deletions apps/css-workshop/src/pages/select.astro
Original file line number Diff line number Diff line change
Expand Up @@ -507,56 +507,55 @@ import Icon_ from '../components/Icon.astro';

<section id='demo-multi'>
<div class='iui-input-with-icon'>
<div tabindex='0' class='iui-select-button iui-field' data-iui-size='small'>
<span class='iui-content'>
<div class='iui-select-tag-container'>
<multi-select-tag value='Option 1' dismissible></multi-select-tag>
<multi-select-tag value='Option 2' dismissible></multi-select-tag>
<multi-select-tag value='Option 3' dismissible></multi-select-tag>
</div>
</span>
<div tabindex='0' class='iui-select-button iui-field' data-iui-size='small' data-iui-multi>
</div>
<Icon_ svg='caret-down-small' class='iui-end-icon' />
<span class='iui-content'>
<div class='iui-select-tag-container'>
<multi-select-tag value='Option 1' dismissible></multi-select-tag>
<multi-select-tag value='Option 2' dismissible></multi-select-tag>
<multi-select-tag value='Option 3' dismissible></multi-select-tag>
</div>
</span>
</div>

<div class='iui-input-with-icon'>
<div tabindex='0' class='iui-select-button iui-field'>
<span class='iui-content'>
<div class='iui-select-tag-container'>
<multi-select-tag value='Option 1' dismissible></multi-select-tag>
<multi-select-tag value='Option 2' dismissible></multi-select-tag>
<multi-select-tag value='Option 3' dismissible></multi-select-tag>
</div>
</span>
</div>
<div tabindex='0' class='iui-select-button iui-field' data-iui-multi></div>
<Icon_ svg='caret-down-small' class='iui-end-icon' />
<span class='iui-content'>
<div class='iui-select-tag-container'>
<multi-select-tag value='Option 1' dismissible></multi-select-tag>
<multi-select-tag value='Option 2' dismissible></multi-select-tag>
<multi-select-tag value='Option 3' dismissible></multi-select-tag>
</div>
</span>
</div>

<div class='iui-input-with-icon'>
<div tabindex='0' class='iui-select-button iui-field' data-iui-size='large'>
<span class='iui-content'>
<div class='iui-select-tag-container'>
<multi-select-tag value='Option 1' dismissible></multi-select-tag>
<multi-select-tag value='Option 2' dismissible></multi-select-tag>
<multi-select-tag value='Option 3' dismissible></multi-select-tag>
</div>
</span>
<div tabindex='0' class='iui-select-button iui-field' data-iui-size='large' data-iui-multi>
</div>
<Icon_ svg='caret-down-small' class='iui-end-icon' />
<span class='iui-content'>
<div class='iui-select-tag-container'>
<multi-select-tag value='Option 1' dismissible></multi-select-tag>
<multi-select-tag value='Option 2' dismissible></multi-select-tag>
<multi-select-tag value='Option 3' dismissible></multi-select-tag>
</div>
</span>
</div>

<div class='iui-input-with-icon' style='width: 480px'>
<div tabindex='0' class='iui-select-button iui-field' data-iui-size='large'>
<span class='iui-content'>
<div class='iui-select-tag-container'>
<multi-select-tag value='Option 1' dismissible></multi-select-tag>
<multi-select-tag value='Option 2' dismissible></multi-select-tag>
<multi-select-tag value='Option 3' dismissible></multi-select-tag>
<multi-select-tag value='+5 more'></multi-select-tag>
</div>
</span>
<div tabindex='0' class='iui-select-button iui-field' data-iui-size='large' data-iui-multi>
</div>
<Icon_ svg='caret-down-small' class='iui-end-icon' />
<span class='iui-content'>
<div class='iui-select-tag-container'>
<multi-select-tag value='Option 1' dismissible></multi-select-tag>
<multi-select-tag value='Option 2' dismissible></multi-select-tag>
<multi-select-tag value='Option 3' dismissible></multi-select-tag>
<multi-select-tag value='+5 more'></multi-select-tag>
</div>
</span>
</div>
</section>
</Layout>
14 changes: 14 additions & 0 deletions packages/itwinui-css/src/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@
color: inherit;
}

&:where([data-iui-multi]) ~ :where(.iui-content) {
grid-area: 1 / -1;
padding-inline-start: var(--iui-size-s);
padding-inline-end: var(--iui-component-height);
z-index: 1;
pointer-events: none; // to prevent blocking clicks on the select-button

> * {
pointer-events: auto; // this is mainly for custom renderer (as a fallback).
}
}

&.iui-placeholder,
&:has(option[value='']:checked) {
color: var(--iui-color-text-placeholder);
Expand Down Expand Up @@ -88,6 +100,7 @@
align-items: center;
gap: var(--iui-size-2xs);
overflow: hidden;
pointer-events: none; // to prevent blocking clicks on the select-button (nested container)

> * + * {
margin-inline-start: var(--iui-size-2xs);
Expand All @@ -105,6 +118,7 @@
block-size: 80%;
max-inline-size: 100%;
max-block-size: calc(var(--iui-size-s) * 3);
pointer-events: auto; // parent has pointer-events: none
}

@mixin iui-select-tag-label {
Expand Down
39 changes: 20 additions & 19 deletions packages/itwinui-react/src/core/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -456,23 +456,14 @@ const CustomSelect = React.forwardRef((props, forwardedRef) => {
},
triggerProps?.className,
)}
data-iui-multi={multiple}
>
{(!selectedItems || selectedItems.length === 0) && (
<Box as='span' className='iui-content'>
{placeholder}
</Box>
)}
{isMultipleEnabled(selectedItems, multiple) ? (
<MultipleSelectButton
selectedItems={selectedItems}
selectedItemsRenderer={
selectedItemRenderer as (
options: SelectOption<unknown>[],
) => JSX.Element
}
tagRenderer={tagRenderer}
/>
) : (
{!isMultipleEnabled(selectedItems, multiple) ? (
<SingleSelectButton
selectedItem={selectedItems}
selectedItemRenderer={
Expand All @@ -481,12 +472,21 @@ const CustomSelect = React.forwardRef((props, forwardedRef) => {
) => JSX.Element
}
/>
) : (
<AutoclearingHiddenLiveRegion text={liveRegionSelection} />
)}
</SelectButton>
<SelectEndIcon disabled={disabled} isOpen={isOpen} />

{multiple ? (
<AutoclearingHiddenLiveRegion text={liveRegionSelection} />
{isMultipleEnabled(selectedItems, multiple) ? (
<MultipleSelectButton
selectedItems={selectedItems}
selectedItemsRenderer={
selectedItemRenderer as (
options: SelectOption<unknown>[],
) => JSX.Element
}
tagRenderer={tagRenderer}
/>
) : null}
</InputWithIcon>

Expand Down Expand Up @@ -774,12 +774,13 @@ const MultipleSelectButton = <T,>({

return (
<>
{selectedItems &&
selectedItemsRenderer &&
selectedItemsRenderer(selectedItems)}
{selectedItems && !selectedItemsRenderer && (
{selectedItems && (
<Box as='span' className='iui-content'>
<SelectTagContainer tags={selectedItemsElements} />
{selectedItemsRenderer ? (
selectedItemsRenderer(selectedItems)
) : (
<SelectTagContainer tags={selectedItemsElements} />
)}
</Box>
)}
</>
Expand Down

0 comments on commit 880d4f8

Please sign in to comment.