Skip to content

Commit 0934684

Browse files
committed
Make rich text action implement label protocol
1 parent 0fafbdd commit 0934684

File tree

4 files changed

+46
-44
lines changed

4 files changed

+46
-44
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ This release starts moving types and views that relate to other types into the t
1717
* `RichTextLabelValue` is a new protocol to harmonize label-compatible label values.
1818

1919
### 💡 Adjustments
20-
20+
2121
* Many value types implement `RichTextLabelValue` to get a `label` property.
22+
* All types that implement `RichTextLabelValue` get a `label` that has improved accessibility.
2223

2324
### 🐛 Bug Fixes
2425

Sources/RichTextKit/Actions/RichTextAction+Button.swift

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public extension RichTextAction {
4444

4545
public var body: some View {
4646
SwiftUI.Button(action: triggerAction) {
47-
action.icon
47+
action.label
48+
.labelStyle(.iconOnly)
4849
.frame(maxHeight: fillVertically ? .infinity : nil)
4950
.contentShape(Rectangle())
5051
}
5152
.keyboardShortcut(for: action)
52-
.accessibilityLabel(action.title)
5353
.disabled(!context.canHandle(action))
5454
}
5555
}
@@ -68,48 +68,50 @@ struct RichTextAction_Button_Previews: PreviewProvider {
6868

6969
@StateObject
7070
private var context = RichTextContext()
71+
72+
func button(
73+
for action: RichTextAction
74+
) -> some View {
75+
RichTextAction.Button(
76+
action: action,
77+
context: context,
78+
fillVertically: true
79+
)
80+
}
7181

7282
var body: some View {
73-
HStack {
74-
RichTextAction.Button(
75-
action: .copy,
76-
context: context,
77-
fillVertically: true
78-
)
79-
RichTextAction.Button(
80-
action: .redoLatestChange,
81-
context: context,
82-
fillVertically: true
83-
)
84-
RichTextAction.Button(
85-
action: .undoLatestChange,
86-
context: context,
87-
fillVertically: true
88-
)
89-
RichTextAction.Button(
90-
action: .stepFontSize(points: 1),
91-
context: context,
92-
fillVertically: true
93-
)
94-
RichTextAction.Button(
95-
action: .stepFontSize(points: -1),
96-
context: context,
97-
fillVertically: true
98-
)
99-
RichTextAction.Button(
100-
action: .decreaseIndent(),
101-
context: context,
102-
fillVertically: true
103-
)
104-
RichTextAction.Button(
105-
action: .increaseIndent(),
106-
context: context,
107-
fillVertically: true
108-
)
83+
VStack {
84+
Group {
85+
HStack {
86+
button(for: .copy)
87+
button(for: .dismissKeyboard)
88+
button(for: .print)
89+
button(for: .redoLatestChange)
90+
button(for: .undoLatestChange)
91+
}
92+
HStack {
93+
ForEach(RichTextAlignment.allCases) {
94+
button(for: .setAlignment($0))
95+
}
96+
}
97+
HStack {
98+
button(for: .stepFontSize(points: 1))
99+
button(for: .stepFontSize(points: -1))
100+
button(for: .stepIndent(points: 1))
101+
button(for: .stepIndent(points: -1))
102+
button(for: .stepSuperscript(steps: 1))
103+
button(for: .stepSuperscript(steps: -1))
104+
}
105+
HStack {
106+
ForEach(RichTextStyle.allCases) {
107+
button(for: .toggleStyle($0))
108+
}
109+
}
110+
}
111+
.fixedSize(horizontal: false, vertical: true)
112+
.padding()
113+
.buttonStyle(.bordered)
109114
}
110-
.fixedSize(horizontal: false, vertical: true)
111-
.padding()
112-
.buttonStyle(.bordered)
113115
}
114116
}
115117

Sources/RichTextKit/Actions/RichTextAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import SwiftUI
1515
This type also serves as a type namespace for other related
1616
types and views, like ``RichTextAction/Button``.
1717
*/
18-
public enum RichTextAction: Identifiable, Equatable {
18+
public enum RichTextAction: Identifiable, Equatable, RichTextLabelValue {
1919

2020
/// Copy the currently selected text, if any.
2121
case copy

Sources/RichTextKit/Views/RichTextLabelValue.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public extension RichTextLabelValue {
2626
icon: { icon }
2727
)
2828
.tag(self)
29-
.accessibilityLabel(title)
3029
}
3130
}
3231

0 commit comments

Comments
 (0)