Skip to content

Commit 349ca07

Browse files
authored
fix: rework Search clear button focus geometry (#22006)
1 parent 39eca8a commit 349ca07

1 file changed

Lines changed: 20 additions & 38 deletions

File tree

packages/styles/scss/components/search/_search.scss

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,8 @@
154154
inset-block-start: 0;
155155
inset-inline-end: 0;
156156

157-
&::before {
158-
position: absolute;
159-
display: block;
160-
background-color: $field;
161-
block-size: calc(100% - 2px);
162-
content: '';
163-
inline-size: 2px;
164-
inset-block-start: convert.to-rem(1px);
165-
inset-inline-start: 0;
166-
transition: background-color $duration-fast-02
167-
motion(standard, productive);
168-
169-
@media screen and (prefers-reduced-motion: reduce) {
170-
transition: none;
171-
}
172-
}
173-
174157
&:hover {
175158
border-block-end: 1px solid $border-strong;
176-
177-
&::before {
178-
background-color: $field-hover;
179-
}
180159
}
181160
}
182161

@@ -191,7 +170,10 @@
191170
}
192171
}
193172

173+
// Keep the clear icon above the hover fill overlay.
194174
.#{$prefix}--search-close svg {
175+
position: relative;
176+
z-index: 1;
195177
fill: inherit;
196178
}
197179

@@ -200,19 +182,14 @@
200182
display: flex;
201183
align-items: center;
202184
justify-content: center;
203-
border-width: 1px 0;
185+
border-width: 0 0 1px;
204186
border-style: solid;
205187
border-color: transparent;
206188
block-size: convert.to-rem(40px);
207189
cursor: pointer;
208190
fill: $icon-primary;
209191
inline-size: convert.to-rem(40px);
210192
opacity: 1;
211-
transition:
212-
opacity $duration-fast-02 motion(standard, productive),
213-
background-color $duration-fast-02 motion(standard, productive),
214-
outline $duration-fast-02 motion(standard, productive),
215-
border $duration-fast-02 motion(standard, productive);
216193
visibility: inherit;
217194

218195
&:hover {
@@ -230,6 +207,22 @@
230207
}
231208
}
232209

210+
// Preserve the field focus outline while the clear button is hovered.
211+
.#{$prefix}--search-input:focus ~ .#{$prefix}--search-close:hover {
212+
background-color: transparent;
213+
border-block-end-color: transparent;
214+
outline: none;
215+
216+
&::after {
217+
position: absolute;
218+
background-color: $field-hover;
219+
content: '';
220+
inset-block: $spacing-01;
221+
inset-inline: 0 $spacing-01;
222+
pointer-events: none;
223+
}
224+
}
225+
233226
.#{$prefix}--search--disabled .#{$prefix}--search-close,
234227
.#{$prefix}--search--disabled.#{$prefix}--search--expandable
235228
.#{$prefix}--search-magnifier {
@@ -250,17 +243,6 @@
250243
fill: $icon-on-color-disabled;
251244
}
252245

253-
.#{$prefix}--search-close:focus,
254-
.#{$prefix}--search-close:active {
255-
&::before {
256-
background-color: $focus;
257-
}
258-
}
259-
260-
.#{$prefix}--search-input:focus ~ .#{$prefix}--search-close:hover {
261-
@include focus-outline('outline');
262-
}
263-
264246
// Small
265247
.#{$prefix}--search--sm {
266248
.#{$prefix}--search-close,

0 commit comments

Comments
 (0)