Skip to content

Commit 6760ec2

Browse files
feat(button): add noWrap property (#4779)
1 parent c4772a8 commit 6760ec2

File tree

9 files changed

+81
-15
lines changed

9 files changed

+81
-15
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ executors:
1010
parameters:
1111
current_golden_images_hash:
1212
type: string
13-
default: 05cb901762d5af33e21e113ed598cecea3488def
13+
default: 3bb8a93772e35ef3bb5e156f76b7c8bd72786144
1414
wireit_cache_name:
1515
type: string
1616
default: wireit

packages/button/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"@spectrum-web-components/shared": "^0.48.1"
9292
},
9393
"devDependencies": {
94-
"@spectrum-css/button": "^13.1.1"
94+
"@spectrum-css/button": "^13.3.0"
9595
},
9696
"types": "./src/index.d.ts",
9797
"customElements": "custom-elements.json",

packages/button/src/Button.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ export class Button extends SizedMixin(ButtonBase, { noDefaultSize: true }) {
156156
this.treatment = quiet ? 'outline' : 'fill';
157157
}
158158

159+
/**
160+
* Disables text wrapping within the button component's label.
161+
* Please note that this option is not a part of the design specification
162+
* and should be used carefully, with consideration of this overflow behavior
163+
* and the readability of the button's content.
164+
*/
165+
@property({ type: Boolean, attribute: 'no-wrap', reflect: true })
166+
public noWrap = false;
167+
159168
public get quiet(): boolean {
160169
return this.treatment === 'outline';
161170
}

packages/button/src/spectrum-button.css

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ governing permissions and limitations under the License.
134134
}
135135

136136
#label {
137-
text-align: center;
138137
place-self: center;
139138
}
140139

@@ -315,6 +314,8 @@ governing permissions and limitations under the License.
315314
--mod-button-padding-label-to-icon,
316315
var(--spectrum-button-padding-label-to-icon)
317316
);
317+
max-inline-size: none;
318+
max-inline-size: var(--mod-button-max-inline-size, none);
318319
min-inline-size: var(
319320
--mod-button-min-width,
320321
var(--spectrum-button-min-width)
@@ -400,6 +401,7 @@ governing permissions and limitations under the License.
400401
--mod-button-line-height,
401402
var(--spectrum-button-line-height)
402403
);
404+
text-align: center;
403405
text-align: var(--mod-button-text-align, center);
404406
align-self: start;
405407
padding-block-start: calc(
@@ -413,6 +415,7 @@ governing permissions and limitations under the License.
413415
}
414416

415417
[name='icon'] + #label {
418+
text-align: start;
416419
text-align: var(--mod-button-text-align-with-icon, start);
417420
}
418421

@@ -512,6 +515,10 @@ governing permissions and limitations under the License.
512515
var(--spectrum-button-content-color-default)
513516
)
514517
);
518+
transition:
519+
border 0.13s linear,
520+
color 0.13s linear,
521+
background-color 0.13s linear;
515522
transition:
516523
border
517524
var(
@@ -639,6 +646,7 @@ governing permissions and limitations under the License.
639646
::slotted([slot='icon']) {
640647
visibility: visible;
641648
opacity: 1;
649+
transition: opacity 0.13s ease-in-out;
642650
transition: opacity
643651
var(
644652
--mod-button-animation-duration,
@@ -650,6 +658,9 @@ governing permissions and limitations under the License.
650658
.spectrum-ProgressCircle {
651659
visibility: hidden;
652660
opacity: 0;
661+
transition:
662+
opacity 0.13s ease-in-out,
663+
visibility 0s linear 0.13s;
653664
transition:
654665
opacity
655666
var(
@@ -673,6 +684,7 @@ governing permissions and limitations under the License.
673684
:host([pending]) .spectrum-ProgressCircle {
674685
visibility: visible;
675686
opacity: 1;
687+
transition: opacity 0.13s ease-in-out;
676688
transition: opacity
677689
var(
678690
--mod-button-animation-duration,
@@ -681,6 +693,12 @@ governing permissions and limitations under the License.
681693
ease-in-out;
682694
}
683695

696+
:host([no-wrap]) #label {
697+
text-overflow: ellipsis;
698+
white-space: nowrap;
699+
overflow: hidden;
700+
}
701+
684702
:host([static='black']),
685703
:host([static='white']) {
686704
--spectrum-button-focus-indicator-color: var(
@@ -691,13 +709,31 @@ governing permissions and limitations under the License.
691709

692710
@media (forced-colors: active) {
693711
:host {
712+
--highcontrast-button-content-color-default: ButtonText;
713+
--highcontrast-button-content-color-hover: ButtonText;
714+
--highcontrast-button-content-color-focus: ButtonText;
715+
--highcontrast-button-content-color-down: ButtonText;
716+
--highcontrast-button-border-color-default: ButtonBorder;
717+
--highcontrast-button-border-color-hover: ButtonBorder;
718+
--highcontrast-button-border-color-focus: ButtonBorder;
719+
--highcontrast-button-border-color-down: ButtonBorder;
720+
--highcontrast-button-background-color-default: ButtonFace;
721+
--highcontrast-button-background-color-hover: ButtonFace;
722+
--highcontrast-button-background-color-down: ButtonFace;
723+
--highcontrast-button-background-color-focus: ButtonFace;
724+
--highcontrast-button-background-color-disabled: ButtonFace;
694725
--highcontrast-button-content-color-disabled: GrayText;
695726
--highcontrast-button-border-color-disabled: GrayText;
696727
--mod-progress-circle-track-border-color: ButtonText;
697728
--mod-progress-circle-track-border-color-over-background: ButtonText;
698729
--mod-progress-circle-thickness: var(
699730
--spectrum-progress-circle-thickness-medium
700731
);
732+
--mod-button-animation-duration: 0s;
733+
}
734+
735+
#label {
736+
forced-color-adjust: none;
701737
}
702738

703739
:host(:focus-visible):after {
@@ -713,17 +749,17 @@ governing permissions and limitations under the License.
713749
:host([variant='accent'][treatment='fill']) {
714750
--highcontrast-button-background-color-default: ButtonText;
715751
--highcontrast-button-content-color-default: ButtonFace;
752+
--highcontrast-button-content-color-hover: HighlightText;
753+
--highcontrast-button-content-color-down: HighlightText;
754+
--highcontrast-button-content-color-focus: HighlightText;
716755
--highcontrast-button-background-color-disabled: ButtonFace;
717756
--highcontrast-button-background-color-hover: Highlight;
718757
--highcontrast-button-background-color-down: Highlight;
719758
--highcontrast-button-background-color-focus: Highlight;
720-
--highcontrast-button-content-color-hover: ButtonFace;
721-
--highcontrast-button-content-color-down: ButtonFace;
722-
--highcontrast-button-content-color-focus: ButtonFace;
723-
}
724-
725-
:host([variant='accent'][treatment='fill']) #label {
726-
forced-color-adjust: none;
759+
--highcontrast-button-border-color-default: ButtonText;
760+
--highcontrast-button-border-color-hover: Highlight;
761+
--highcontrast-button-border-color-focus: Highlight;
762+
--highcontrast-button-border-color-down: Highlight;
727763
}
728764
}
729765

packages/button/src/spectrum-config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ const config = {
7070
converter.classToHost(),
7171
converter.classToAttribute('spectrum-Button--quiet'),
7272
converter.classToAttribute('spectrum-Button--emphasized'),
73+
converter.classToAttribute(
74+
'spectrum-Button--noWrap',
75+
'no-wrap'
76+
),
7377
converter.classToAttribute('is-selected', 'selected'),
7478
converter.classToAttribute('is-focused', 'focused'),
7579
converter.classToAttribute('is-pending', 'pending'),

packages/button/stories/button-primary-fill.stories.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
99
OF ANY KIND, either express or implied. See the License for the specific language
1010
governing permissions and limitations under the License.
1111
*/
12-
import { TemplateResult } from '@spectrum-web-components/base';
12+
import { html, TemplateResult } from '@spectrum-web-components/base';
1313
import {
14+
renderButton,
1415
renderButtonSet,
1516
renderIconSizeOverridden,
1617
renderLink,
@@ -54,6 +55,20 @@ export const minWidthButton = (props: Properties): TemplateResult =>
5455

5556
minWidthButton.storyName = 'min-width';
5657

58+
export const noWrapButton = (props: Properties): TemplateResult =>
59+
renderButton({ noWrap, content, ...props });
60+
61+
const noWrap = true;
62+
const content = html`
63+
Really long content that should not wrap, if it does wrap then we have a
64+
problem. Do we have a problem? I hope we don't have a problem. Is this long
65+
enough to show we do not have a problem? Awesome, we do not have a problem.
66+
Really long content that should not wrap, if it does wrap then we have a
67+
problem. Do we have a problem? I hope we don't have a problem. Is this long
68+
enough to show we do not have a problem? Awesome, we do not have a problem.
69+
`;
70+
noWrapButton.storyName = 'no-wrap';
71+
5772
export const link = (props: Properties): TemplateResult => renderLink(props);
5873

5974
link.storyName = 'href';

packages/button/stories/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export function renderButton(properties: Properties): TemplateResult {
122122
?icon-only=${properties.iconOnly}
123123
?pending=${!!properties.pending}
124124
?quiet="${!!properties.quiet}"
125+
?no-wrap="${!!properties.noWrap}"
125126
size=${properties.size}
126127
target=${ifDefined(properties.target)}
127128
treatment=${ifDefined(properties.treatment)}

packages/button/stories/template.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface Properties {
2727
size?: 's' | 'm' | 'l' | 'xl';
2828
href?: string;
2929
target?: '_blank' | '_parent' | '_self' | '_top';
30+
noWrap?: boolean;
3031
iconOnly?: boolean;
3132
}
3233

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5038,10 +5038,10 @@
50385038
resolved "https://registry.yarnpkg.com/@spectrum-css/breadcrumb/-/breadcrumb-9.1.3.tgz#c1ea002a4e1f3f0b792b951b0768b1a35460da8a"
50395039
integrity sha512-BHzCr5Q5f2+CQxSlq8rDM03wzvn9EozoI/xDP4kw5WrWI7gXUmCJc2iHzu94pQuWprSxoEE+wfx+r63VQ9gsOQ==
50405040

5041-
"@spectrum-css/button@^13.1.1":
5042-
version "13.1.1"
5043-
resolved "https://registry.yarnpkg.com/@spectrum-css/button/-/button-13.1.1.tgz#42be27e8f8d03a7af3eca17fb7566ca2b8cc5f24"
5044-
integrity sha512-GyLNIErpuSfES0GftmzGgsBLgzdMd10PVU34TgYuRz9Ad3DeRpfT1PzA9jKDjqXXCtf91tB7lMkYPdUCHcHLgA==
5041+
"@spectrum-css/button@^13.3.0":
5042+
version "13.3.0"
5043+
resolved "https://registry.yarnpkg.com/@spectrum-css/button/-/button-13.3.0.tgz#37690a6768cc9c82544014d1fb3115ef552a51c7"
5044+
integrity sha512-plco8vVj+YiSHZW1LfxWqwmQmKJHd5Ri6XqA47fdF9cU6gGjEvNXd3ZRt8qPI4oZ/RPMPxEkLsgdk44fD5d/Qw==
50455045

50465046
"@spectrum-css/buttongroup@^7.1.1":
50475047
version "7.1.1"

0 commit comments

Comments
 (0)