Improve element stacking in modals on tablet and mobile (#35733)

* Add updated versions of sr-only and not-sr-only mixins

* Improve element stacking in modals on tablet and mobile

* Add comment suggestion

* Change sr-only for screen-reader-only which is more descriptive
This commit is contained in:
Maikel David Pérez Gómez 2022-11-30 13:28:00 -03:00 committed by GitHub
parent 1e9fff35c0
commit 25a7c35cf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 91 additions and 12 deletions

View File

@ -1,7 +1,7 @@
// Rem output with px fallback // Rem output with px fallback
@mixin font-size( $sizeValue: 16, $lineHeight: false ) { @mixin font-size( $sizeValue: 16, $lineHeight: false ) {
font-size: $sizeValue + px; font-size: $sizeValue + px;
font-size: math.div($sizeValue, 16) + rem; font-size: math.div( $sizeValue, 16 ) + rem;
@if ( $lineHeight ) { @if ( $lineHeight ) {
line-height: $lineHeight; line-height: $lineHeight;
} }
@ -106,7 +106,7 @@
background-color: $studio-white; background-color: $studio-white;
color: $gray-900; color: $gray-900;
box-shadow: inset 0 0 0 1px $gray-400, inset 0 0 0 2px $studio-white, box-shadow: inset 0 0 0 1px $gray-400, inset 0 0 0 2px $studio-white,
0 1px 1px rgba($gray-900, 0.2); 0 1px 1px rgba( $gray-900, 0.2 );
} }
@mixin button-style__active() { @mixin button-style__active() {
@ -145,7 +145,6 @@
} }
/* stylelint-enable */ /* stylelint-enable */
// Gutenberg Switch. // Gutenberg Switch.
@mixin switch-style__focus-active() { @mixin switch-style__focus-active() {
box-shadow: 0 0 0 2px $studio-white, 0 0 0 3px $gray-700; box-shadow: 0 0 0 2px $studio-white, 0 0 0 3px $gray-700;
@ -158,19 +157,20 @@
// Sets positions for children of grid elements // Sets positions for children of grid elements
@mixin set-grid-item-position( $wrap-after, $number-of-items ) { @mixin set-grid-item-position( $wrap-after, $number-of-items ) {
@for $i from 1 through $number-of-items { @for $i from 1 through $number-of-items {
&:nth-child(#{$i}) { &:nth-child( #{$i} ) {
grid-column-start: #{($i - 1) % $wrap-after + 1}; grid-column-start: #{( $i - 1 ) % $wrap-after + 1};
grid-column-end: #{($i - 1) % $wrap-after + 2}; grid-column-end: #{( $i - 1 ) % $wrap-after + 2};
grid-row-start: #{floor(math.div($i - 1, $wrap-after)) + 1}; grid-row-start: #{floor( math.div( $i - 1, $wrap-after ) ) + 1};
grid-row-end: #{floor(math.div($i - 1, $wrap-after)) + 2}; grid-row-end: #{floor( math.div( $i - 1, $wrap-after ) ) + 2};
} }
} }
} }
// Hide an element from sighted users, but availble to screen reader users. // Hide an element from sighted users, but availble to screen reader users.
// @deprecated in favor of screen-reader-only
@mixin visually-hidden() { @mixin visually-hidden() {
clip: rect(1px, 1px, 1px, 1px); clip: rect( 1px, 1px, 1px, 1px );
clip-path: inset(50%); clip-path: inset( 50% );
height: 1px; height: 1px;
width: 1px; width: 1px;
margin: -1px; margin: -1px;
@ -180,7 +180,20 @@
word-wrap: normal !important; word-wrap: normal !important;
} }
@mixin screen-reader-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect( 0, 0, 0, 0 );
white-space: nowrap;
border-width: 0;
}
// Unhide a visually hidden element // Unhide a visually hidden element
// @deprecated in favor of not-screen-reader-only
@mixin visually-shown() { @mixin visually-shown() {
clip: auto; clip: auto;
clip-path: none; clip-path: none;
@ -190,6 +203,17 @@
overflow: hidden; overflow: hidden;
} }
@mixin not-screen-reader-only {
position: static;
width: auto;
height: auto;
padding: 0;
margin: 0;
overflow: visible;
clip: auto;
white-space: normal;
}
// Create a string-repeat function // Create a string-repeat function
@function str-repeat( $character, $n ) { @function str-repeat( $character, $n ) {
@if $n == 0 { @if $n == 0 {

View File

@ -0,0 +1,4 @@
Significance: patch
Type: enhancement
Add updated versions of screen-reader-only and not-screen-reader-only mixins

View File

@ -32,6 +32,12 @@
width: 100%; width: 100%;
margin-top: $gap-large; margin-top: $gap-large;
@include breakpoint( '<782px' ) {
thead {
@include screen-reader-only();
}
}
th { th {
text-align: left; text-align: left;
color: $gray-700; color: $gray-700;
@ -54,10 +60,39 @@
td:not(:last-child) { td:not(:last-child) {
margin-right: $gap; margin-right: $gap;
} }
@include breakpoint( '<782px' ) {
position: relative;
grid-template-columns: 1fr;
// Added the width of the trash icon as padding
// so that it can be displayed correctly
padding-right: 42px;
}
@include breakpoint( '>782px' ) {
.woocommerce-experimental-select-control__label {
@include screen-reader-only();
}
.woocommerce-experimental-select-control__combo-box-wrapper {
margin-bottom: 0;
}
}
} }
&__table-attribute-trash-column { &__table-attribute-trash-column {
display: flex; display: flex;
justify-content: center; justify-content: center;
@include breakpoint( '<782px' ) {
position: absolute;
top: 0;
right: 0;
bottom: 0;
align-items: center;
}
.components-button.has-icon {
padding: 8px;
}
} }
} }

View File

@ -124,6 +124,9 @@ export const AddAttributeModal: React.FC< AddAttributeModalProps > = ( {
} }
}; };
const attributeLabel = __( 'Attribute', 'woocommerce' );
const valueLabel = __( 'Values', 'woocommerce' );
return ( return (
<> <>
<Form< AttributeForm > <Form< AttributeForm >
@ -167,8 +170,8 @@ export const AddAttributeModal: React.FC< AddAttributeModalProps > = ( {
<table className="woocommerce-add-attribute-modal__table"> <table className="woocommerce-add-attribute-modal__table">
<thead> <thead>
<tr className="woocommerce-add-attribute-modal__table-header"> <tr className="woocommerce-add-attribute-modal__table-header">
<th>Attribute</th> <th>{ attributeLabel }</th>
<th>Values</th> <th>{ valueLabel }</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -185,6 +188,9 @@ export const AddAttributeModal: React.FC< AddAttributeModalProps > = ( {
'woocommerce' 'woocommerce'
) } ) }
value={ attribute } value={ attribute }
label={
attributeLabel
}
onChange={ ( onChange={ (
val val
) => { ) => {
@ -246,6 +252,9 @@ export const AddAttributeModal: React.FC< AddAttributeModalProps > = ( {
? [] ? []
: attribute.terms : attribute.terms
} }
label={
valueLabel
}
onChange={ ( onChange={ (
val val
) => ) =>
@ -269,6 +278,9 @@ export const AddAttributeModal: React.FC< AddAttributeModalProps > = ( {
value={ value={
attribute.options attribute.options
} }
label={
valueLabel
}
onChange={ ( onChange={ (
val val
) => ) =>

View File

@ -0,0 +1,4 @@
Significance: patch
Type: enhancement
Improve element stacking in modals on tablet and mobile