Skip to content

Commit 76ef3ed

Browse files
committed
feat(select): add sizes for ionic theme
1 parent a1f3fcc commit 76ef3ed

File tree

6 files changed

+62
-4
lines changed

6 files changed

+62
-4
lines changed

core/api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,7 @@ ion-select,prop,okText,string,'OK',false,false
20652065
ion-select,prop,placeholder,string | undefined,undefined,false,false
20662066
ion-select,prop,selectedText,null | string | undefined,undefined,false,false
20672067
ion-select,prop,shape,"round" | undefined,undefined,false,false
2068+
ion-select,prop,size,"large" | "medium" | "small" | undefined,undefined,false,false
20682069
ion-select,prop,theme,"ios" | "md" | "ionic",undefined,false,false
20692070
ion-select,prop,toggleIcon,string | undefined,undefined,false,false
20702071
ion-select,prop,value,any,undefined,false,false

core/src/components.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,6 +3283,10 @@ export namespace Components {
32833283
* The shape of the select. If "round" it will have an increased border radius.
32843284
*/
32853285
"shape"?: 'round';
3286+
/**
3287+
* Set to `"small"` for a select with less height, `"medium"` for the default select height, or `"large"` for a select with more height. Defaults to `"medium"` for the ionic theme, and undefined for all other themes.
3288+
*/
3289+
"size"?: 'small' | 'medium' | 'large';
32863290
/**
32873291
* The theme determines the visual appearance of the component.
32883292
*/
@@ -8707,6 +8711,10 @@ declare namespace LocalJSX {
87078711
* The shape of the select. If "round" it will have an increased border radius.
87088712
*/
87098713
"shape"?: 'round';
8714+
/**
8715+
* Set to `"small"` for a select with less height, `"medium"` for the default select height, or `"large"` for a select with more height. Defaults to `"medium"` for the ionic theme, and undefined for all other themes.
8716+
*/
8717+
"size"?: 'small' | 'medium' | 'large';
87108718
/**
87118719
* The theme determines the visual appearance of the component.
87128720
*/

core/src/components/select/select.ionic.scss

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@
8585

8686
position: relative;
8787

88-
height: globals.$ion-scale-1200;
89-
9088
background: var(--background);
9189

9290
box-sizing: border-box;
@@ -183,3 +181,26 @@
183181
:host(.select-disabled) .select-icon {
184182
color: globals.$ion-primitives-neutral-500;
185183
}
184+
185+
// Sizes
186+
// ----------------------------------------------------------------
187+
188+
// Small
189+
// ---------------------------------------------
190+
191+
:host(.select-size-small) .select-wrapper-inner {
192+
height: globals.$ion-scale-1000;
193+
}
194+
195+
// Medium
196+
// ---------------------------------------------
197+
198+
:host(.select-size-medium) .select-wrapper-inner {
199+
height: globals.$ion-scale-1200;
200+
}
201+
202+
// Large
203+
// ---------------------------------------------
204+
:host(.select-size-large) .select-wrapper-inner {
205+
height: globals.$ion-scale-1400;
206+
}

core/src/components/select/select.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ export class Select implements ComponentInterface {
200200
*/
201201
@Prop({ mutable: true }) value?: any | null;
202202

203+
/**
204+
* Set to `"small"` for a select with less height,
205+
* `"medium"` for the default select height,
206+
* or `"large"` for a select with more height.
207+
*
208+
* Defaults to `"medium"` for the ionic theme, and undefined for all other themes.
209+
*/
210+
@Prop() size?: 'small' | 'medium' | 'large';
211+
203212
/**
204213
* Emitted when the value has changed.
205214
*
@@ -816,6 +825,22 @@ export class Select implements ComponentInterface {
816825
this.ionBlur.emit();
817826
};
818827

828+
private getSize(): string | undefined {
829+
const theme = getIonTheme(this);
830+
const { size } = this;
831+
832+
// TODO(ROU-11370): Remove theme check when sizes are defined for all themes.
833+
if (theme !== 'ionic') {
834+
return undefined;
835+
}
836+
837+
if (size === undefined) {
838+
return 'medium';
839+
}
840+
841+
return size;
842+
}
843+
819844
private renderLabel() {
820845
const { label } = this;
821846

@@ -1055,6 +1080,7 @@ export class Select implements ComponentInterface {
10551080
const justifyEnabled = !hasFloatingOrStackedLabel && justify !== undefined;
10561081
const rtl = isRTL(el) ? 'rtl' : 'ltr';
10571082
const inItem = hostContext('ion-item', this.el);
1083+
const size = this.getSize();
10581084
const shouldRenderHighlight = theme === 'md' && fill !== 'outline' && !inItem;
10591085

10601086
const hasValue = this.hasValue();
@@ -1101,6 +1127,7 @@ export class Select implements ComponentInterface {
11011127
[`select-justify-${justify}`]: justifyEnabled,
11021128
[`select-shape-${shape}`]: shape !== undefined,
11031129
[`select-label-placement-${labelPlacement}`]: true,
1130+
[`select-size-${size}`]: size !== undefined,
11041131
})}
11051132
>
11061133
<label class="select-wrapper" id="select-label">

packages/angular/src/directives/proxies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,15 +2066,15 @@ export declare interface IonSegmentView extends Components.IonSegmentView {
20662066

20672067

20682068
@ProxyCmp({
2069-
inputs: ['cancelText', 'color', 'compareWith', 'disabled', 'expandedIcon', 'fill', 'interface', 'interfaceOptions', 'justify', 'label', 'labelPlacement', 'mode', 'multiple', 'name', 'okText', 'placeholder', 'selectedText', 'shape', 'theme', 'toggleIcon', 'value'],
2069+
inputs: ['cancelText', 'color', 'compareWith', 'disabled', 'expandedIcon', 'fill', 'interface', 'interfaceOptions', 'justify', 'label', 'labelPlacement', 'mode', 'multiple', 'name', 'okText', 'placeholder', 'selectedText', 'shape', 'size', 'theme', 'toggleIcon', 'value'],
20702070
methods: ['open']
20712071
})
20722072
@Component({
20732073
selector: 'ion-select',
20742074
changeDetection: ChangeDetectionStrategy.OnPush,
20752075
template: '<ng-content></ng-content>',
20762076
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
2077-
inputs: ['cancelText', 'color', 'compareWith', 'disabled', 'expandedIcon', 'fill', 'interface', 'interfaceOptions', 'justify', 'label', 'labelPlacement', 'mode', 'multiple', 'name', 'okText', 'placeholder', 'selectedText', 'shape', 'theme', 'toggleIcon', 'value'],
2077+
inputs: ['cancelText', 'color', 'compareWith', 'disabled', 'expandedIcon', 'fill', 'interface', 'interfaceOptions', 'justify', 'label', 'labelPlacement', 'mode', 'multiple', 'name', 'okText', 'placeholder', 'selectedText', 'shape', 'size', 'theme', 'toggleIcon', 'value'],
20782078
})
20792079
export class IonSelect {
20802080
protected el: HTMLElement;

packages/vue/src/proxies.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ export const IonSelect = /*@__PURE__*/ defineContainer<JSX.IonSelect, JSX.IonSel
800800
'expandedIcon',
801801
'shape',
802802
'value',
803+
'size',
803804
'ionChange',
804805
'ionCancel',
805806
'ionDismiss',

0 commit comments

Comments
 (0)