Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Fixed issue with -ArgumentList and buttons. #1615

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/UniversalDashboard.MaterialUI/Components/button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const UdButton = props => {

const handleClick = () => {
if (props.onClick == null) return
props.notifyOfEvent('onClick', '')
props.onClick();
}

var icon = props.icon ? (
Expand Down
12 changes: 4 additions & 8 deletions src/UniversalDashboard.MaterialUI/Scripts/button.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function New-UDButton {
[switch]$FullWidth,

[Parameter (Position = 7)]
[object]$OnClick,
[Endpoint]$OnClick,

[Parameter (Position = 8)]
[ValidateSet("small", "medium", "large")]
Expand All @@ -83,13 +83,9 @@ function New-UDButton {

End {

if ($null -ne $OnClick) {
if ($OnClick -is [scriptblock]) {
$OnClick = New-UDEndpoint -Endpoint $OnClick -Id ($Id + "onClick")
}
elseif ($OnClick -isnot [UniversalDashboard.Models.Endpoint]) {
throw "OnClick must be a script block or UDEndpoint"
}
if ($OnClick)
{
$OnClick.Register($Id, $PSCmdlet)
}

@{
Expand Down
5 changes: 5 additions & 0 deletions src/UniversalDashboard.MaterialUI/Tests/button.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ Enter-SeUrl -Target $Driver -Url "http://localhost:10000/button"

Describe "button" {

It 'works with argumentlist' {
Find-SeElement -Id 'arugmentList' -Driver $Driver | Invoke-SeClick
Get-TestData | Should be "Some Text"
}

It 'has default variant' {
$Element = Find-SeElement -Id 'btnDefault' -Driver $Driver
$Element.GetAttribute("class").Contains('MuiButton-contained') | should be $true
Expand Down
7 changes: 7 additions & 0 deletions src/UniversalDashboard.MaterialUI/dashboard.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ New-UDDashboard -Title "Dashboard" -Theme (get-udtheme basic) -Pages @(
New-UDButton -Text "Submit" -Id "btnClick" -Icon $Icon -OnClick {
Set-TestData -Data "OnClick"
}

$MyVariable = "Some Text"
New-UDButton -Text "Click me!" -Id 'arugmentList' -OnClick (
New-UDEndpoint -Endpoint {
Set-TestData -Data $ArgumentList[0]
} -ArgumentList @($MyVariable)
)
}

New-UDPage -Name 'Card' -Content {
Expand Down