Skip to content

Commit

Permalink
Make the inputmode modifier accept an enum (#162)
Browse files Browse the repository at this point in the history
* Make the inputmode modifier accept an enum

* Deprecate the old modifier

* Rename a case of the mode enum

* Add a test
  • Loading branch information
mattesmohr authored Nov 30, 2024
1 parent ce83258 commit 18061c6
Show file tree
Hide file tree
Showing 17 changed files with 640 additions and 12 deletions.
15 changes: 9 additions & 6 deletions Sources/HTMLKit/Abstraction/Attributes/BasicAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1121,16 +1121,19 @@ extension IsMapAttribute where Self: EmptyNode {
}
}

/// The protocol provides the element with the inputmode handler.
/// A type that provides the `inputMode` modifier.
@_documentation(visibility: internal)
public protocol InputModeAttribute: Attribute {

/// The function represents the html-attribute 'inputmode'.
/// Set the virtual keyboard mode for the editable element.
///
/// ```html
/// <tag inputmode="" />
/// ```swift
/// Input()
/// .inputMode(.numeric)
/// ```
func inputMode(_ value: String) -> Self
///
/// - Parameter value: The mode to set on
func inputMode(_ value: Values.Mode) -> Self
}

extension InputModeAttribute where Self: ContentNode {
Expand Down
5 changes: 5 additions & 0 deletions Sources/HTMLKit/Abstraction/Elements/BasicElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,14 @@ extension Html: GlobalAttributes, GlobalEventAttributes {
return self
}

@available(*, deprecated, message: "The inputmode attribute is actually an enumerated attribute. Use the inputMode(_: Mode) modifier instead.")
public func inputMode(_ value: String) -> Html {
return mutate(inputmode: value)
}

public func inputMode(_ value: Values.Mode) -> Html {
return mutate(inputmode: value.rawValue)
}

public func `is`(_ value: String) -> Html {
return mutate(is: value)
Expand Down
Loading

0 comments on commit 18061c6

Please sign in to comment.