diff --git a/core/api.txt b/core/api.txt index 8a02f2a89b..aaaa6faa01 100644 --- a/core/api.txt +++ b/core/api.txt @@ -916,6 +916,7 @@ ion-picker-column,prop,disabled,boolean,false,false,false ion-picker-column,prop,items,PickerColumnItem[],[],false,false ion-picker-column,prop,mode,"ios" | "md",undefined,false,false ion-picker-column,prop,value,number | string | undefined,undefined,false,false +ion-picker-column,method,setFocus,setFocus() => Promise ion-picker-column,event,ionChange,PickerColumnItem,true ion-picker-column-option,shadow diff --git a/core/src/components.d.ts b/core/src/components.d.ts index e720e6d515..b66abce3b3 100644 --- a/core/src/components.d.ts +++ b/core/src/components.d.ts @@ -1977,6 +1977,10 @@ export namespace Components { */ "numericInput": boolean; "scrollActiveItemIntoView": () => Promise; + /** + * Sets focus on the scrollable container within the picker column. Use this method instead of the global `pickerColumn.focus()`. + */ + "setFocus": () => Promise; /** * Sets the value prop and fires the ionChange event. This is used when we need to fire ionChange from user-generated events that cannot be caught with normal input/change event listeners. */ diff --git a/core/src/components/datetime/datetime.scss b/core/src/components/datetime/datetime.scss index db00e15c82..babbbe7bdb 100644 --- a/core/src/components/datetime/datetime.scss +++ b/core/src/components/datetime/datetime.scss @@ -25,19 +25,6 @@ overflow: hidden; } -/** - * When using the wheel picker to switch - * between months, sometimes the allowed - * dates may be filtered. As a result, it - * is possible to get a layout shift as - * the picker column will shrink to fit the - * widest item in the column. Setting a minimum - * width avoids this layout shifting. - */ -ion-picker-column { - min-width: 26px; -} - :host(.datetime-size-fixed) { width: auto; height: auto; diff --git a/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-ios-ltr-Mobile-Chrome-linux.png b/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-ios-ltr-Mobile-Chrome-linux.png index 26407824fb..9bc2b80193 100644 Binary files a/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-ios-ltr-Mobile-Chrome-linux.png and b/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-ios-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-ios-ltr-Mobile-Firefox-linux.png b/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-ios-ltr-Mobile-Firefox-linux.png index b12a1f8b12..8d81fe1fa6 100644 Binary files a/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-ios-ltr-Mobile-Firefox-linux.png and b/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-ios-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-ios-ltr-Mobile-Safari-linux.png b/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-ios-ltr-Mobile-Safari-linux.png index af2ff059e1..38f09fb91d 100644 Binary files a/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-ios-ltr-Mobile-Safari-linux.png and b/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-ios-ltr-Mobile-Safari-linux.png differ diff --git a/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-md-ltr-Mobile-Chrome-linux.png b/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-md-ltr-Mobile-Chrome-linux.png index 6dc7b71ce3..3731e82d5c 100644 Binary files a/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-md-ltr-Mobile-Chrome-linux.png and b/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-md-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-md-ltr-Mobile-Firefox-linux.png b/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-md-ltr-Mobile-Firefox-linux.png index ee7bf829ec..a06ae51d4e 100644 Binary files a/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-md-ltr-Mobile-Firefox-linux.png and b/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-md-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-md-ltr-Mobile-Safari-linux.png b/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-md-ltr-Mobile-Safari-linux.png index a560454e4d..403c627d5f 100644 Binary files a/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-md-ltr-Mobile-Safari-linux.png and b/core/src/components/datetime/test/custom/datetime.e2e.ts-snapshots/datetime-custom-time-picker-md-ltr-Mobile-Safari-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-ltr-Mobile-Chrome-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-ltr-Mobile-Chrome-linux.png index 56375e49c2..3a56f7a941 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-ltr-Mobile-Chrome-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-ltr-Mobile-Firefox-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-ltr-Mobile-Firefox-linux.png index 877e6eebf3..1517f7c966 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-ltr-Mobile-Firefox-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-ltr-Mobile-Safari-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-ltr-Mobile-Safari-linux.png index 5e5aca9604..63840441b7 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-ltr-Mobile-Safari-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-ltr-Mobile-Safari-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-rtl-Mobile-Chrome-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-rtl-Mobile-Chrome-linux.png index 9b4bce97bd..3310836997 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-rtl-Mobile-Chrome-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-rtl-Mobile-Chrome-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-rtl-Mobile-Firefox-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-rtl-Mobile-Firefox-linux.png index 5b1d76ba84..84272ed8a7 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-rtl-Mobile-Firefox-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-rtl-Mobile-Firefox-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-rtl-Mobile-Safari-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-rtl-Mobile-Safari-linux.png index 6cc4006fbb..9cf42cc0a9 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-rtl-Mobile-Safari-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-ios-rtl-Mobile-Safari-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-ltr-Mobile-Chrome-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-ltr-Mobile-Chrome-linux.png index 4524ca6c27..f80559f6c3 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-ltr-Mobile-Chrome-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-ltr-Mobile-Firefox-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-ltr-Mobile-Firefox-linux.png index f2773c86bb..4bbe2da728 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-ltr-Mobile-Firefox-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-ltr-Mobile-Safari-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-ltr-Mobile-Safari-linux.png index 1b151c9ade..8e19649b19 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-ltr-Mobile-Safari-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-ltr-Mobile-Safari-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-rtl-Mobile-Chrome-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-rtl-Mobile-Chrome-linux.png index 7f1b2f17d4..5b7a49549a 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-rtl-Mobile-Chrome-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-rtl-Mobile-Chrome-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-rtl-Mobile-Firefox-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-rtl-Mobile-Firefox-linux.png index adbc9d1c1f..aaa3cf1ac9 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-rtl-Mobile-Firefox-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-rtl-Mobile-Firefox-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-rtl-Mobile-Safari-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-rtl-Mobile-Safari-linux.png index 43338a9f47..aaae021b26 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-rtl-Mobile-Safari-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-base-md-rtl-Mobile-Safari-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-ltr-Mobile-Chrome-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-ltr-Mobile-Chrome-linux.png index fb65b78b42..85452e324e 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-ltr-Mobile-Chrome-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-ltr-Mobile-Firefox-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-ltr-Mobile-Firefox-linux.png index 81a0f160e7..598871dc55 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-ltr-Mobile-Firefox-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-ltr-Mobile-Safari-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-ltr-Mobile-Safari-linux.png index 1caa240c29..7b12da629e 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-ltr-Mobile-Safari-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-ltr-Mobile-Safari-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-rtl-Mobile-Chrome-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-rtl-Mobile-Chrome-linux.png index 89ec396220..9ed964d3ef 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-rtl-Mobile-Chrome-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-rtl-Mobile-Chrome-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-rtl-Mobile-Firefox-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-rtl-Mobile-Firefox-linux.png index 201d760f4e..31d9a87934 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-rtl-Mobile-Firefox-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-rtl-Mobile-Firefox-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-rtl-Mobile-Safari-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-rtl-Mobile-Safari-linux.png index 8b96c75435..9fe1114583 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-rtl-Mobile-Safari-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-ios-rtl-Mobile-Safari-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-ltr-Mobile-Chrome-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-ltr-Mobile-Chrome-linux.png index 5110e8b679..cfb1f266e7 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-ltr-Mobile-Chrome-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-ltr-Mobile-Firefox-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-ltr-Mobile-Firefox-linux.png index 1f0bd6cc9c..de59c033dc 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-ltr-Mobile-Firefox-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-ltr-Mobile-Safari-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-ltr-Mobile-Safari-linux.png index 9f202c3224..71775a0e60 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-ltr-Mobile-Safari-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-ltr-Mobile-Safari-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-rtl-Mobile-Chrome-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-rtl-Mobile-Chrome-linux.png index 62e1d096d1..911b1c90d4 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-rtl-Mobile-Chrome-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-rtl-Mobile-Chrome-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-rtl-Mobile-Firefox-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-rtl-Mobile-Firefox-linux.png index 16c4c82ce0..a3d1d1666d 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-rtl-Mobile-Firefox-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-rtl-Mobile-Firefox-linux.png differ diff --git a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-rtl-Mobile-Safari-linux.png b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-rtl-Mobile-Safari-linux.png index e3c68df1bc..b964fcaf54 100644 Binary files a/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-rtl-Mobile-Safari-linux.png and b/core/src/components/datetime/test/position/datetime.e2e.ts-snapshots/datetime-position-popover-md-rtl-Mobile-Safari-linux.png differ diff --git a/core/src/components/datetime/test/position/index.html b/core/src/components/datetime/test/position/index.html index 3da97aa417..51909e8e21 100644 --- a/core/src/components/datetime/test/position/index.html +++ b/core/src/components/datetime/test/position/index.html @@ -25,7 +25,7 @@ Present Popover - + diff --git a/core/src/components/datetime/test/prefer-wheel/datetime.e2e.ts b/core/src/components/datetime/test/prefer-wheel/datetime.e2e.ts index 79ad3c64a6..7690360de5 100644 --- a/core/src/components/datetime/test/prefer-wheel/datetime.e2e.ts +++ b/core/src/components/datetime/test/prefer-wheel/datetime.e2e.ts @@ -447,6 +447,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => { await page.waitForSelector('.datetime-ready'); const dateColumn = page.locator('.date-column'); + const dateColumnScrollEl = dateColumn.locator('.picker-opts'); const dateValues = dateColumn.locator('.picker-item:not(.picker-item-empty)'); expect(await dateValues.count()).toBe(90); @@ -455,7 +456,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => { * Select 1st item to change the dates rendered */ await expect(dateValues.nth(0)).toHaveAttribute('data-value', '2022-1-1'); - await dateColumn.evaluate((el: HTMLElement) => (el.scrollTop = 0)); + await dateColumnScrollEl.evaluate((el: HTMLElement) => (el.scrollTop = 0)); await page.waitForChanges(); await expect(dateValues.nth(0)).toHaveAttribute('data-value', '2021-12-1'); @@ -632,6 +633,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => { await page.waitForSelector('.datetime-ready'); const dateColumn = page.locator('.date-column'); + const dateColumnScrollEl = dateColumn.locator('.picker-opts'); const dateValues = dateColumn.locator('.picker-item:not(.picker-item-empty)'); expect(await dateValues.count()).toBe(90); @@ -640,7 +642,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => { * Select 1st item to change the dates rendered */ await expect(dateValues.nth(0)).toHaveAttribute('data-value', '2022-1-1'); - await dateColumn.evaluate((el: HTMLElement) => (el.scrollTop = 0)); + await dateColumnScrollEl.evaluate((el: HTMLElement) => (el.scrollTop = 0)); await page.waitForChanges(); await expect(dateValues.nth(0)).toHaveAttribute('data-value', '2021-12-1'); diff --git a/core/src/components/picker-column/picker-column.scss b/core/src/components/picker-column/picker-column.scss index 3e0a1937ae..d040174459 100644 --- a/core/src/components/picker-column/picker-column.scss +++ b/core/src/components/picker-column/picker-column.scss @@ -4,13 +4,53 @@ // -------------------------------------------------- :host { - @include padding(0px, 16px, 0px, 16px); + display: flex; + + align-items: center; + + justify-content: center; + + max-width: 100%; height: 200px; + font-size: 22px; + + text-align: center; +} + +.picker-opts { + /** + * This padding must be set here and not on the + * host to ensure that the focus highlight on the + * column is not overly narrow. + */ + @include padding(0px, 16px, 0px, 16px); + + /** + * When using reactive data, such as in datetime's + * wheel picker, there may be layout shifts between + * individual columns in a picker as the columns + * shrink to fit the widest item in the column. + * Setting a minimum width avoids this layout shifting. + * + * Note that we need this min-width set on the same + * element as the vertical padding (i.e. not on the + * host). + */ + min-width: 26px; + max-height: 200px; + outline: none; - font-size: 22px; + /** + * Added so that text-align can be set on the host + * from external components. For example, datetime + * changes the alignment of specific columns in its + * wheel pickers. + */ + text-align: inherit; + scroll-snap-type: y mandatory; /** @@ -22,17 +62,45 @@ // Hide scrollbars on Firefox scrollbar-width: none; - - text-align: center; } /** * Hide scrollbars on Chrome and Safari */ -:host::-webkit-scrollbar { +.picker-opts::-webkit-scrollbar { display: none; } +::slotted([slot="prefix"]), ::slotted([slot="suffix"]) { + max-width: 200px; + + text-overflow: ellipsis; + + white-space: nowrap; + + overflow: hidden; +} + +::slotted([slot="prefix"]) { + /** + * This is added in addition to the column's own padding so that there is white + * space between the slot and the column's focus highlight. + */ + @include padding(0, 16px); + + justify-content: end; +} + +::slotted([slot="suffix"]) { + /** + * This is added in addition to the column's own padding so that there is white + * space between the slot and the column's focus highlight. + */ + @include padding(0, 16px); + + justify-content: start; +} + :host .picker-item { @include padding(0); @include margin(0); @@ -93,7 +161,7 @@ } @media (any-hover: hover) { - :host(:focus) { + :host(:focus) .picker-opts { outline: none; background: current-color(base, 0.2); diff --git a/core/src/components/picker-column/picker-column.tsx b/core/src/components/picker-column/picker-column.tsx index f615eed530..a6726cc231 100644 --- a/core/src/components/picker-column/picker-column.tsx +++ b/core/src/components/picker-column/picker-column.tsx @@ -13,6 +13,9 @@ import type { PickerColumnItem } from './picker-column-interfaces'; /** * @virtualProp {"ios" | "md"} mode - The mode determines which platform styles to use. + * + * @slot prefix - Content to show on the left side of the picker options. + * @slot suffix - Content to show on the right side of the picker options. */ @Component({ tag: 'ion-picker-column', @@ -23,6 +26,7 @@ import type { PickerColumnItem } from './picker-column-interfaces'; shadow: true, }) export class PickerColumn implements ComponentInterface { + private scrollEl?: HTMLDivElement | null; private destroyScrollListener?: () => void; private isScrolling = false; private scrollEndCallback?: () => void; @@ -175,13 +179,25 @@ export class PickerColumn implements ComponentInterface { } } + /** + * Sets focus on the scrollable container within the picker column. + * Use this method instead of the global `pickerColumn.focus()`. + */ + @Method() + async setFocus() { + if (this.scrollEl) { + this.scrollEl.focus(); + } + } + private centerPickerItemInView = (target: HTMLElement, smooth = true, canExitInputMode = true) => { - const { el, isColumnVisible } = this; - if (isColumnVisible) { + const { isColumnVisible, scrollEl } = this; + + if (isColumnVisible && scrollEl) { // (Vertical offset from parent) - (three empty picker rows) + (half the height of the target to ensure the scroll triggers) const top = target.offsetTop - 3 * target.clientHeight + target.clientHeight / 2; - if (el.scrollTop !== top) { + if (scrollEl.scrollTop !== top) { /** * Setting this flag prevents input * mode from exiting in the picker column's @@ -190,7 +206,7 @@ export class PickerColumn implements ComponentInterface { * of these can cause a scroll to occur. */ this.canExitInputMode = canExitInputMode; - el.scroll({ + scrollEl.scroll({ top, left: 0, behavior: smooth ? 'smooth' : undefined, @@ -267,13 +283,15 @@ export class PickerColumn implements ComponentInterface { * be disabled on Android. */ const enableHaptics = isPlatform('ios'); - const { el } = this; + const { el, scrollEl } = this; let timeout: ReturnType | undefined; let activeEl: HTMLElement | null = this.activeItem; const scrollCallback = () => { raf(() => { + if (!scrollEl) return; + if (timeout) { clearTimeout(timeout); timeout = undefined; @@ -288,7 +306,7 @@ export class PickerColumn implements ComponentInterface { * Select item in the center of the column * which is the month/year that we want to select */ - const bbox = el.getBoundingClientRect(); + const bbox = scrollEl.getBoundingClientRect(); const centerX = bbox.x + bbox.width / 2; const centerY = bbox.y + bbox.height / 2; @@ -378,10 +396,12 @@ export class PickerColumn implements ComponentInterface { * does not fire when component is initially shown. */ raf(() => { - el.addEventListener('scroll', scrollCallback); + if (!scrollEl) return; + + scrollEl.addEventListener('scroll', scrollCallback); this.destroyScrollListener = () => { - el.removeEventListener('scroll', scrollCallback); + scrollEl.removeEventListener('scroll', scrollCallback); }; }); }; @@ -434,62 +454,71 @@ export class PickerColumn implements ComponentInterface { - - - - {items.map((item, index) => { - const isItemDisabled = pickerDisabled || item.disabled || false; + +
{ + this.scrollEl = el; + }} + > + + + + {items.map((item, index) => { + const isItemDisabled = pickerDisabled || item.disabled || false; - { - /* - Users should be able to tab - between multiple columns. As a result, - we set tabindex here so that tabbing switches - between columns instead of buttons. Users - can still use arrow keys on the keyboard to - navigate the column up and down. - */ - } - return ( - - ); - })} - - - + ); } diff --git a/core/src/components/picker-column/test/disabled/picker-column.e2e.ts-snapshots/picker-disabled-column-md-ltr-Mobile-Chrome-linux.png b/core/src/components/picker-column/test/disabled/picker-column.e2e.ts-snapshots/picker-disabled-column-md-ltr-Mobile-Chrome-linux.png index 6968e26058..5895f3ee25 100644 Binary files a/core/src/components/picker-column/test/disabled/picker-column.e2e.ts-snapshots/picker-disabled-column-md-ltr-Mobile-Chrome-linux.png and b/core/src/components/picker-column/test/disabled/picker-column.e2e.ts-snapshots/picker-disabled-column-md-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/picker-column/test/disabled/picker-column.e2e.ts-snapshots/picker-disabled-column-md-ltr-Mobile-Firefox-linux.png b/core/src/components/picker-column/test/disabled/picker-column.e2e.ts-snapshots/picker-disabled-column-md-ltr-Mobile-Firefox-linux.png index 02bc29af22..03159c4cec 100644 Binary files a/core/src/components/picker-column/test/disabled/picker-column.e2e.ts-snapshots/picker-disabled-column-md-ltr-Mobile-Firefox-linux.png and b/core/src/components/picker-column/test/disabled/picker-column.e2e.ts-snapshots/picker-disabled-column-md-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/picker-column/test/disabled/picker-column.e2e.ts-snapshots/picker-disabled-column-md-ltr-Mobile-Safari-linux.png b/core/src/components/picker-column/test/disabled/picker-column.e2e.ts-snapshots/picker-disabled-column-md-ltr-Mobile-Safari-linux.png index d94af6fdb6..2b52b5bdb9 100644 Binary files a/core/src/components/picker-column/test/disabled/picker-column.e2e.ts-snapshots/picker-disabled-column-md-ltr-Mobile-Safari-linux.png and b/core/src/components/picker-column/test/disabled/picker-column.e2e.ts-snapshots/picker-disabled-column-md-ltr-Mobile-Safari-linux.png differ diff --git a/core/src/components/picker-column/test/slots/index.html b/core/src/components/picker-column/test/slots/index.html new file mode 100644 index 0000000000..57f5b8dac9 --- /dev/null +++ b/core/src/components/picker-column/test/slots/index.html @@ -0,0 +1,50 @@ + + + + + Picker Column - Slots + + + + + + + + + + + + Picker Column - Basic + + + + + +
Prefix
+
Suffix
+
+
+ + +
Prefix
+
Long Suffix Long Suffix Long Suffix
+
+
+
+ +
+ + diff --git a/core/src/components/picker-column/test/slots/picker-column.e2e.ts b/core/src/components/picker-column/test/slots/picker-column.e2e.ts new file mode 100644 index 0000000000..7e4b5ce678 --- /dev/null +++ b/core/src/components/picker-column/test/slots/picker-column.e2e.ts @@ -0,0 +1,58 @@ +import { expect } from '@playwright/test'; +import { configs, test } from '@utils/test/playwright'; + +configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => { + test.describe(title('picker-column: slots'), () => { + test('should not have visual regressions with prefix and suffix', async ({ page }) => { + await page.setContent( + ` + + +
Prefix
+
Suffix
+
+
+ + + `, + config + ); + + const picker = page.locator('ion-picker'); + await expect(picker).toHaveScreenshot(screenshot(`picker-prefix-suffix`)); + }); + + test('should not have visual regressions with a long prefix and suffix', async ({ page }) => { + await page.setContent( + ` + + +
Long prefix long prefix long prefix
+
Long suffix long suffix long suffix
+
+
+ + + `, + config + ); + + const picker = page.locator('ion-picker'); + await expect(picker).toHaveScreenshot(screenshot(`picker-long-prefix-suffix`)); + }); + }); +}); diff --git a/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-ios-ltr-Mobile-Chrome-linux.png b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-ios-ltr-Mobile-Chrome-linux.png new file mode 100644 index 0000000000..bd46589f87 Binary files /dev/null and b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-ios-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-ios-ltr-Mobile-Firefox-linux.png b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-ios-ltr-Mobile-Firefox-linux.png new file mode 100644 index 0000000000..7ed8c026bb Binary files /dev/null and b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-ios-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-ios-ltr-Mobile-Safari-linux.png b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-ios-ltr-Mobile-Safari-linux.png new file mode 100644 index 0000000000..1bd6ef9349 Binary files /dev/null and b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-ios-ltr-Mobile-Safari-linux.png differ diff --git a/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-md-ltr-Mobile-Chrome-linux.png b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-md-ltr-Mobile-Chrome-linux.png new file mode 100644 index 0000000000..58a8fa85ae Binary files /dev/null and b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-md-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-md-ltr-Mobile-Firefox-linux.png b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-md-ltr-Mobile-Firefox-linux.png new file mode 100644 index 0000000000..22385e3b0a Binary files /dev/null and b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-md-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-md-ltr-Mobile-Safari-linux.png b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-md-ltr-Mobile-Safari-linux.png new file mode 100644 index 0000000000..abc8bdde05 Binary files /dev/null and b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-long-prefix-suffix-md-ltr-Mobile-Safari-linux.png differ diff --git a/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-ios-ltr-Mobile-Chrome-linux.png b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-ios-ltr-Mobile-Chrome-linux.png new file mode 100644 index 0000000000..35c2a4a7af Binary files /dev/null and b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-ios-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-ios-ltr-Mobile-Firefox-linux.png b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-ios-ltr-Mobile-Firefox-linux.png new file mode 100644 index 0000000000..d00a871ad8 Binary files /dev/null and b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-ios-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-ios-ltr-Mobile-Safari-linux.png b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-ios-ltr-Mobile-Safari-linux.png new file mode 100644 index 0000000000..0a6d49fb68 Binary files /dev/null and b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-ios-ltr-Mobile-Safari-linux.png differ diff --git a/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-md-ltr-Mobile-Chrome-linux.png b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-md-ltr-Mobile-Chrome-linux.png new file mode 100644 index 0000000000..249d08e1d8 Binary files /dev/null and b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-md-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-md-ltr-Mobile-Firefox-linux.png b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-md-ltr-Mobile-Firefox-linux.png new file mode 100644 index 0000000000..42dcad8dd7 Binary files /dev/null and b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-md-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-md-ltr-Mobile-Safari-linux.png b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-md-ltr-Mobile-Safari-linux.png new file mode 100644 index 0000000000..f0d5decfd0 Binary files /dev/null and b/core/src/components/picker-column/test/slots/picker-column.e2e.ts-snapshots/picker-prefix-suffix-md-ltr-Mobile-Safari-linux.png differ diff --git a/core/src/components/picker/test/basic/picker.e2e.ts b/core/src/components/picker/test/basic/picker.e2e.ts index e464a48bed..a0a46952dd 100644 --- a/core/src/components/picker/test/basic/picker.e2e.ts +++ b/core/src/components/picker/test/basic/picker.e2e.ts @@ -131,7 +131,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => const firstColumn = page.locator('ion-picker-column#first'); const secondColumn = page.locator('ion-picker-column#second'); - await secondColumn.focus(); + await secondColumn.evaluate((el: HTMLIonPickerColumnElement) => el.setFocus()); await expect(secondColumn).toBeFocused(); await page.waitForChanges(); diff --git a/core/src/components/picker/test/basic/picker.e2e.ts-snapshots/picker-popover-diff-md-ltr-Mobile-Chrome-linux.png b/core/src/components/picker/test/basic/picker.e2e.ts-snapshots/picker-popover-diff-md-ltr-Mobile-Chrome-linux.png index 578e53e8d8..98ea20a8ad 100644 Binary files a/core/src/components/picker/test/basic/picker.e2e.ts-snapshots/picker-popover-diff-md-ltr-Mobile-Chrome-linux.png and b/core/src/components/picker/test/basic/picker.e2e.ts-snapshots/picker-popover-diff-md-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/picker/test/keyboard-entry/picker.e2e.ts b/core/src/components/picker/test/keyboard-entry/picker.e2e.ts index ae2210e0c0..cee9d192af 100644 --- a/core/src/components/picker/test/keyboard-entry/picker.e2e.ts +++ b/core/src/components/picker/test/keyboard-entry/picker.e2e.ts @@ -32,7 +32,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => const column = page.locator('ion-picker-column'); const ionChange = await page.spyOnEvent('ionChange'); - await column.focus(); + await column.evaluate((el: HTMLIonPickerColumnElement) => el.setFocus()); await page.keyboard.press('Digit2'); @@ -126,7 +126,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => const column = page.locator('ion-picker-column'); const ionChange = await page.spyOnEvent('ionChange'); - await column.focus(); + await column.evaluate((el: HTMLIonPickerColumnElement) => el.setFocus()); await page.keyboard.press('Digit0'); diff --git a/packages/angular/src/directives/proxies.ts b/packages/angular/src/directives/proxies.ts index c6e7c3bb3b..281b5a7e02 100644 --- a/packages/angular/src/directives/proxies.ts +++ b/packages/angular/src/directives/proxies.ts @@ -1446,7 +1446,8 @@ export declare interface IonPicker extends Components.IonPicker { @ProxyCmp({ - inputs: ['color', 'disabled', 'items', 'mode', 'value'] + inputs: ['color', 'disabled', 'items', 'mode', 'value'], + methods: ['setFocus'] }) @Component({ selector: 'ion-picker-column', diff --git a/packages/angular/standalone/src/directives/proxies.ts b/packages/angular/standalone/src/directives/proxies.ts index e9a5b52a5b..57a2af555a 100644 --- a/packages/angular/standalone/src/directives/proxies.ts +++ b/packages/angular/standalone/src/directives/proxies.ts @@ -1441,7 +1441,8 @@ export declare interface IonPicker extends Components.IonPicker { @ProxyCmp({ defineCustomElementFn: defineIonPickerColumn, - inputs: ['color', 'disabled', 'items', 'mode', 'value'] + inputs: ['color', 'disabled', 'items', 'mode', 'value'], + methods: ['setFocus'] }) @Component({ selector: 'ion-picker-column',